我是WPF的新手,我尝试创建xaml逻辑,以根据ViewModel上的AllowMiscTitle的值显示/隐藏控件.XAML中包含两个领域的标准砖的组合框("先生","太太",...,"其他")时,"其他"选择我想要的文本框来显示.
我创建了以下xaml:
<DockPanel Validation.Error="Validation_Error" HorizontalAlignment="Stretch">
<ComboBox ItemsSource="{Binding Path=Titles, Mode=OneTime}"
Text="{Binding Path=Title}"/>
<TextBox x:Name="TxtBxTitle" Margin="5,5" Visibility="Visible">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=AllowMiscTitle}" Value="false">
<Setter Property="TextBox.Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DockPanel>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的WPF窗口的背景设置为图像,但是当我尝试运行它时,我得到了这个异常:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '8' and line position '10'.
我不想将图像添加到项目中,因为我希望能够在运行时更改图像.我的目的是使用数据绑定在启动过程中设置背景图片.
源代码:
<Window x:Class="ColinsTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Colin's Test Application"
WindowStyle="None"
WindowState="Maximized">
<Window.Background>
<ImageBrush
ImageSource="DeLaRue-Background.jpg"/>
</Window.Background>
<Grid></Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢