C# 样式中元素的WPF集合属性(Visual.Brush)

C# 样式中元素的WPF集合属性(Visual.Brush),c#,wpf,C#,Wpf,如何设置标签(L_水印)的Content属性? 我尝试了不同的方法,但都不管用。 通常情况下,设置一个元素关于其名称的属性,但在这里它不起作用。 我想在CodeBehind中或通过数据绑定到依赖项属性来实现这一点 my UserControl的XAML: <StackPanel Orientation="Horizontal" Width="155"> <TextBox x:Name="TB_Date" LostFocus="TB_Date_LostFocus" Key

如何设置标签(
L_水印
)的
Content
属性? 我尝试了不同的方法,但都不管用。 通常情况下,设置一个元素关于其名称的属性,但在这里它不起作用。 我想在CodeBehind中或通过数据绑定到依赖项属性来实现这一点

my UserControl的XAML:

<StackPanel Orientation="Horizontal" Width="155">
    <TextBox x:Name="TB_Date" LostFocus="TB_Date_LostFocus" KeyDown="TB_Date_KeyDown" BorderThickness="0" VerticalContentAlignment="Center" Width="125" Height="24">
        <TextBox.Style>
            <Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
                <Style.Resources>
                    <VisualBrush x:Name="VisuBrush" x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
                        <VisualBrush.Visual>
                            <Label x:Name="L_Watermark" Content="{Binding Watermark, UpdateSourceTrigger=PropertyChanged, Mode=OneWay, FallbackValue=Date}" Foreground="LightGray" />
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Style.Resources>
                <Style.Triggers>
                    <Trigger Property="Text" Value="{x:Static sys:String.Empty}">
                        <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
                    </Trigger>
                    <Trigger Property="Text" Value="{x:Null}">
                        <Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
                    </Trigger>
                    <Trigger Property="IsKeyboardFocused" Value="True">
                        <Setter Property="Background" Value="White" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TextBox.Style>
    </TextBox>
    <DatePicker Name="DP_Date" Focusable="False" BorderBrush="{x:Null}" SelectedDateChanged="DP_Date_SelectedDateChanged" Width="30" FirstDayOfWeek="Monday" Height="24"/>
</StackPanel>
public bool HasStartTime
{
    get { return (bool)GetValue(HasStartTimeProperty); }
    set
    {
        SetValue(HasStartTimeProperty, value);
        OnPropertyChanged();
    }
}

// Using a DependencyProperty as the backing store for HasStartTime.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty HasStartTimeProperty =
    DependencyProperty.Register("HasStartTime", typeof(bool), typeof(AdvancedDatePicker), new PropertyMetadata(false));

public string Watermark
{
    get { return (string)GetValue(WatermarkProperty); }
    set
    {
        SetValue(WatermarkProperty, value);
        OnPropertyChanged();
    }
}

// Using a DependencyProperty as the backing store for Watermark.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty WatermarkProperty =
    DependencyProperty.Register("Watermark", typeof(string), typeof(AdvancedDatePicker), new PropertyMetadata("Datum"));
就像
TB\u Date
中的
文本一样,我试图用
L\u Watermark.Content=Watermark

我还尝试使用数据绑定,如:

<Label x:Name="L_Watermark" Content="{Binding Watermark, UpdateSourceTrigger=PropertyChanged, Mode=OneWay, FallbackValue=Date}" Foreground="LightGray" />

您想将属性设置为什么的依赖属性?至少让我们看看你试过什么。“没用”不够具体,无法猜测你做错了什么。让我们看看你是如何“谈论他的名字”的。向我们展示您的XAML或“关于他的名字”的C#代码。这是在ControlTemplate还是DataTemplate中?它属于什么?真的不清楚你想做什么。但是您已经创建了一个名为
VisuBrush
的资源。你想用它做什么?现在我更新了帖子。我希望现在我的问题更清楚了。请注意,您不必实现INotifyPropertyChanged并为依赖属性触发PropertyChanged事件。他们提供了自己的更改通知机制。感谢您的回答,我将删除它。但问题仍然存在。
public bool HasStartTime
{
    get { return (bool)GetValue(HasStartTimeProperty); }
    set
    {
        SetValue(HasStartTimeProperty, value);
        OnPropertyChanged();
    }
}

// Using a DependencyProperty as the backing store for HasStartTime.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty HasStartTimeProperty =
    DependencyProperty.Register("HasStartTime", typeof(bool), typeof(AdvancedDatePicker), new PropertyMetadata(false));

public string Watermark
{
    get { return (string)GetValue(WatermarkProperty); }
    set
    {
        SetValue(WatermarkProperty, value);
        OnPropertyChanged();
    }
}

// Using a DependencyProperty as the backing store for Watermark.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty WatermarkProperty =
    DependencyProperty.Register("Watermark", typeof(string), typeof(AdvancedDatePicker), new PropertyMetadata("Datum"));