我ResourceDictionary
在一个单独的文件中有一个名为MainSkin.xaml
:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="RoundedButton">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Viewbox>
<Grid>
<Grid Name="backgroundGrid" Width="80" Height="80" Visibility="Visible">
<Path Data="Some Data Path here" Stretch="Fill" Fill="#FFFFFFFF" Name="Stroke" Visibility="Visible" />
</Grid>
<Path Data="Some Data Path here" Stretch="Uniform" Fill="#FFF9F9F9" Width="44" Height="44" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
我将这个 ResourceDictionary 放入MergedDictionaries
如下App.Xaml
Application.Resources
:
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
<-- VS is asking for a x:key here, why ? --/>
<ResourceDictionary ----> x:Key="" <----- >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins/MainSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Visual Studio 不停地询问包含 ResourceDictionary(包含 的那个<ResourceDictionary.MergedDictionaries>
)的 ax:Key,你能解释一下为什么,我应该怎么做?