首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >App.xaml中的WPF全球资源

App.xaml中的WPF全球资源
EN

Stack Overflow用户
提问于 2010-06-18 13:47:50
回答 1查看 7.1K关注 0票数 1

我已经创建了一个自定义Treeview控件,并试图从同一项目中的另一个页面访问该控件的HierarchicalDataTemplate资源。

我的this.sceneTemplate属性将变为null。我已经遍历了字典中的所有对象,而且它确实存在。

如何访问此模板?

谢谢

App.xaml

代码语言:javascript
复制
<Application x:Class="Foo.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml" 
    DispatcherUnhandledException="App_DispatcherUnhandledException">
    <Application.Resources>
        <ResourceDictionary>
            <!--Merge the global resource to the application-->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Global.xaml"/>
                <ResourceDictionary Source="Resources/Scrollbar.xaml"/>
                <ResourceDictionary Source="/Controls/TreeView/Themes/Generic.xaml"/>
                <ResourceDictionary Source="/Controls/ListButton/Themes/Generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>
</Application>

在这里,我试图从我的Scene.xaml.cs页面访问资源

代码语言:javascript
复制
 public LeagueDataTemplateSelector()
 {
    if (Application.Current != null)
    {

        this.sceneTemplate = (HierarchicalDataTemplate)Application.Current.FindResource("Scene");
        this.ItemTemplate = (HierarchicalDataTemplate)Application.Current.FindResource("Procedure");
        this.sub1Template = (HierarchicalDataTemplate)Application.Current.FindResource("SubProc1");
        this.sub2Template = (HierarchicalDataTemplate)Application.Current.FindResource("SubProc2");
    }

}

场景HierarchicalDataTemplate

代码语言:javascript
复制
<HierarchicalDataTemplate x:Key="Scene" ItemsSource="{Binding XPath=Level}"
                                ItemContainerStyle="{StaticResource RadTreeViewItemStyleSub1}"
                                ItemTemplate="{StaticResource Procedure}"
                                >
        <Border>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Label VerticalContentAlignment="Center" 
                        BorderThickness="0" 
                        BorderBrush="Transparent" 
                        Foreground="{StaticResource ListItemUnHighlight}" 
                        FontSize="24" 
                        Tag="{Binding XPath=@name}" 
                        MinHeight="55" 
                        Cursor="Hand" 
                        FontFamily="Arial" 
                        KeyboardNavigation.TabNavigation="None" 
                        Name="SubItem" >
                    <Label.ContextMenu>
                        <ContextMenu Name="editMenu">
                            <MenuItem Header="Edit"/>
                        </ContextMenu>
                    </Label.ContextMenu>
                    <TextBlock Text="{Binding XPath=@name}" VerticalAlignment="Center" TextWrapping="Wrap"></TextBlock>
                </Label>
            </Grid>
        </Border>
    </HierarchicalDataTemplate>

更新-答复

我们的程序有一个面包屑控件,它通过使用页面列表来导航。在运行InitializeComponent之前,这个页面列表是在启动屏幕期间添加的。我将它移到页面列表代码之上,现在可以找到App.xaml中的所有内容。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-17 15:05:24

我们的程序有一个面包屑控件,它通过使用页面列表来导航。在运行InitializeComponent之前,这个页面列表是在启动屏幕期间添加的。我将它移到页面列表代码之上,现在可以找到App.xaml中的所有内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3070137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档