2010-06-18 5 views
0

사용자 지정 Treeview 컨트롤을 만들었으며 같은 프로젝트의 다른 페이지에서이 컨트롤의 HierarchicalDataTemplate 리소스에 액세스하려고합니다.WPF 전역 리소스 (App.xaml)

내 this.sceneTemplate 속성이 올 것입니다. 사전에있는 모든 객체를 반복했는데 존재합니다.

어떻게이 템플릿에 액세스 할 수 있습니까? 내 Scene.xaml.cs 페이지

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

<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 [email protected]}" 
         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 [email protected]}" VerticalAlignment="Center" TextWrapping="Wrap"></TextBlock> 
       </Label> 
      </Grid> 
     </Border> 
    </HierarchicalDataTemplate> 
에서 리소스에 액세스하려고

감사

App.xaml

<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> 

업데이트 - 답변

Google 프로그램에는 탐색 할 페이지 목록을 사용하여 작동하는 이동 경로 컨트롤이 있습니다. 이 페이지 목록은 InitializeComponent가 실행되기 전에 스플래시 화면에서 추가되었습니다. 이 코드를 페이지 목록 코드 위로 옮기면 App.xaml의 모든 항목이 검색됩니다.

+0

응용 프로그램 시작 이벤트에서 모든 리소스 사전에 대해 반복 작업을 수행하고 올바른 사전을로드하는지 확인하기 위해 특정 리소스를 검색 할 수 있습니까? – decyclone

+0

올바른 리소스 사전에 있음을 확인했습니다. – Ryan

+0

@ Ryan, 업데이트를 실제 답변으로 게시하는 것이 좋습니다. 며칠 후 수락합니다. 그 질문은 "대답"이라고 표시합니다. – ChrisF

답변

0

Google 프로그램에는 탐색 할 페이지 목록을 사용하여 작동하는 이동 경로 컨트롤이 있습니다. 이 페이지 목록은 InitializeComponent가 실행되기 전에 스플래시 화면에서 추가되었습니다. 이 코드를 페이지 목록 코드 위로 옮기면 App.xaml의 모든 항목이 검색됩니다.