我有一个简单的Window,它引用了App.xaml中的StaticResource.
App.xaml资源定义:
<!-- Standard Text Box Style -->
<Style x:Key="textBoxStyleStd" TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="14" />
</Style>
Run Code Online (Sandbox Code Playgroud)
使用资源的窗口组件:
<TextBlock Grid.Column="1" Grid.Row="0" Name="stationIdTitle"
Style="{StaticResource textBlockStyleStd}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Text="{LocText Key=Title, Dict={StaticResource Dictionary},
Assembly={StaticResource Assembly}}"/>
Run Code Online (Sandbox Code Playgroud)
在尝试对此窗口进行单元测试时,我收到错误:
System.Windows.Markup.XamlParseException:找不到名为"{textBlockStyleStd}"的资源.资源名称区分大小写.标记文件'Zpg; component/guicomponenets/screens/enteredindidscreen.xaml'中对象'stationIdTitle'出错'第23行位置71.
有没有办法解决?我的单元测试代码是:
[Test]
public void TestEnterKeyPressedNoText()
{
IPickingBusinessObject pickingBusinessObject = mock.StrictMock<IPickingBusinessObject>();
EnterStationIdScreen objectUnderTest = new EnterStationIdScreen(pickingBusinessObject);
Assert.AreEqual(Visibility.Visible, objectUnderTest.stationIdError.Visibility);
Assert.AreEqual("werwe", "oksdf");
Replay();
objectUnderTest.EnterKeyPressed();
Verify();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用VS 2010中的wpf和C#开发半大型Windows应用程序.在xaml上工作时,我添加了一个标记,以便所有按钮和数据网格以相同的方式设置样式.我已经将这个块复制并粘贴到我的几个.xaml文件中,并且工作正常.当然,我现在遇到的问题是我已经多次添加并更改了样式.
在不同的Windows之间保持样式一致的最佳方法是什么?它是使用Resources.resx进行子类化还是其他方式?