我想在 UWP 中使用 ResourceDictionary,就像我在 WPF 中使用的一样 在 WPF 中,我在 ResourceDictionary 文件(*Style.xaml)中执行此操作
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:models="using:NWP.Models">
<Style x:key="MenuContent" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<controls:DockPanel>
<ItemsControl ItemsSource="{x:Bind How-Can-I-Bind-Collection-Here?}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:MenuItemModel">
<RadioButton GroupName="MenuItems" IsChecked="{x:Binding IsChecked, Mode=TwoWay}" MinHeight="0" MinWidth="0" Command="{Binding Command}" CommandParameter="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</controls:DockPanel>
</ControlTemplate>
</Setter.Value>
</Style>
</ResourceDictionary>
然后我可以在我的页面中使用这种样式:
<ContentControl Style="{StaticResource MenuContent}">
<StackPanel Orientation="Vertical">
<TextBox/>
<PasswordBox/>
<Button Content="Login"/>
</StackPanel>
</ContentControl>
但是现在,我在纠结如何使用 x:bind 为 ResourceDictionary 中的 ItemsControl 中的 ItemsSource 提供源:
<ItemsControl ItemsSource="{x:Bind How-Can-I-Bind-Collection-Here?}">
我的问题是,如何解决这个问题?