开发者

WPF Theming and dynamic controls

开发者 https://www.devze.com 2022-12-26 06:58 出处:网络
I a开发者_运维技巧m trying to add control to ContentPresenter on then run, but control I\'ve added does not apply theme.

I a开发者_运维技巧m trying to add control to ContentPresenter on then run, but control I've added does not apply theme.

Theres is code with reference to theme in xaml file:

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/PocGraphDataTemplates.xaml" />
        </ResourceDictionary.MergedDictionaries>

Also I've tried to set style in code behind, does not work:

        this.graphLayout.Content = analyzerViewModel.AnalyzedLayout = new PocGraphLayout()
        {
            LayoutAlgorithmType = "FR"
        }; 
        ResourceDictionary rd = new ResourceDictionary();
        rd.Source = new Uri("Resources/PocGraphDataTemplates.xaml", UriKind.Relative);
        analyzerViewModel.AnalyzedLayout.Style = new Style(typeof(PocGraphLayout));
        analyzerViewModel.AnalyzedLayout.Style.Resources.MergedDictionaries.Add(rd);

When control was static everything worked fine:

<ViewModel:PocGraphLayout x:Name="graphLayout"
                                        Graph="{Binding Path=Graph}"
                                        LayoutAlgorithmType="{Binding Path=LayoutAlgorithmType}"
                                        Sample:LayoutManager.ManagedLayout="True"
                                        OverlapRemovalAlgorithmType="FSA"
                                        HighlightAlgorithmType="Simple" />

Any ideas?

PS. I am newbie in wpf.


just see the style applied are using DynamicResource instead of StaticResource

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号