0

我有一个数据模板Resource.xaml

    <DataTemplate x:Key="SplitViewMenuItemWithCount">
    <RelativePanel>
        <RelativePanel RelativePanel.AlignVerticalCenterWithPanel="True" Margin="0,10,0,10">
            <SymbolIcon Foreground="White" Width="25" RelativePanel.AlignVerticalCenterWithPanel="True" Symbol="{Binding Symbol}" x:Name="SymbolIcon" Margin="10,0,0,0"/>
            <StackPanel Visibility="{Binding Count, Converter={StaticResource BooleanToVisibilityConverter}, TargetNullValue=Collapsed, FallbackValue=Collapsed}" x:Name="StackPanelCount" RelativePanel.RightOf="SymbolIcon" Margin="0,20,0,0" CornerRadius="9" Background="White" Width="15" Height="15">
                <TextBlock Text="{Binding Count, FallbackValue='0'}" TextAlignment="Center" FontSize="10" Foreground="{StaticResource AppDarkBlueColor}"/>
            </StackPanel>
            <TextBlock Margin="10,0,0,0" Foreground="White" x:Name="TextBlockMenuItemText" RelativePanel.RightOf="StackPanelCount" Text="{Binding Text}" FontSize="16" Padding="5,3,0,5"/>
        </RelativePanel>
    </RelativePanel>
</DataTemplate>

我将 MainPage.xaml 中的数据模板用作 ListView 的数据模板,但由于我的BooleanToVisibilityConverter. 它在 中找不到转换器Resource.xaml

但是,如果我将数据模板放入其中,MainPage.Resources它会找到转换器(因为它是在那里定义的)。

有什么办法可以保留数据模板Resource.xaml吗?我宁愿把它放在那里而不是放在MainPage.Resources.

4

1 回答 1

2

您必须使用ResourceDictionnary标记将 mainPage.xaml 中的引用添加到 resources.xaml,如下所示:

<Window x:Class="MainPage"  ...  ... >
     <Window.Resources>
         <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/YourProjectDLL;component/Resource.xaml" />
            </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Window.Resources>
     <Grid>
          ... Your window body
     </Grid>
</Window>
于 2015-11-26T14:37:33.093 回答