WPF 因设置不期望的DataContext,导致的绑定异常

在MainWindow中,创建一个背景属性BrushTest,并将其绑定至界面

1 <Window x:Class="WpfApp8.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:WpfApp8" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="450" Width="800" x:Name="TheMainWindow"> 9 <Grid> 10 <local:UserControl1 BackgroundTest="{Binding BrushTest}"/> 11 </Grid> 12 </Window>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyssyw.html