这对我不起作用
<UserControl x:Class="BenchmarkPlus.PMT.UI.Views.Circle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" x:Name="root"
DataContext="{Binding Source={x:Static Brushes.Blue}}">
<UserControl.Resources>
<Style TargetType="Ellipse">
<Setter Property="Fill" Value="{Binding DataContext}" />
</Style>
</UserControl.Resources>
<Grid>
<Ellipse Stroke="Black"></Ellipse>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
简单点DataContext="{x:Static Brushes.Blue}"
改成Value="{Binding DataContext}"
Value="{Binding}"
.
当您在绑定表达式中指定路径时,它始终相对于您的 DataContext,因此当您使用 时{Binding DataContext}
,您实际上绑定到DataContext.DataContext
,这不是您想要的。
归档时间: |
|
查看次数: |
3217 次 |
最近记录: |