UserControl не обновляется после изменения значений в дизайнере - PullRequest
0 голосов
/ 25 мая 2020

Я создал элемент управления TitledTextBox, унаследованный от System. Windows .Control.TextBox.

Я добавил дополнительные свойства зависимости для Title

    public string Title
    {
        get { return (string)GetValue(TitleProperty); }
        set { SetValue(TitleProperty, value); }
    }

    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register("Title", typeof(string), typeof(TitledTextBox), new PropertyMetadata(string.Empty));

    public double TitleSize
    {
        get { return (double)GetValue(TitleSizeProperty); }
        set { SetValue(TitleSizeProperty, value); }
    }

    public static readonly DependencyProperty TitleSizeProperty =
        DependencyProperty.Register("TitleSize", typeof(double), typeof(TitledTextBox), new PropertyMetadata(11.0));

    public Brush TitleForeground
    {
        get { return (Brush)GetValue(TitleForegroundProperty); }
        set { SetValue(TitleForegroundProperty, value); }
    }

    public static readonly DependencyProperty TitleForegroundProperty =
        DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(TitledTextBox), new PropertyMetadata(Brushes.Gray));

    public FontWeight TitleWeight
    {
        get { return (FontWeight)GetValue(TitleWeightProperty); }
        set { SetValue(TitleWeightProperty, value); }
    }

    public static readonly DependencyProperty TitleWeightProperty =
        DependencyProperty.Register("TitleWeight", typeof(FontWeight), typeof(TitledTextBox), new PropertyMetadata(FontWeights.DemiBold));

Во время выполнения он выглядит примерно так.

image

, но при добавлении элемента управления в конструкторе значение заголовка не отображается, даже когда я даю постоянную строку.

Шаблон управления приведен ниже.

             <ControlTemplate TargetType="{x:Type control:TitledTextBox}">
                <Grid Height="{TemplateBinding Height}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{TemplateBinding Title}"
                               FontSize="{TemplateBinding TitleSize}"
                               Foreground="{TemplateBinding TitleForeground}"
                               FontWeight="{TemplateBinding TitleWeight}"/>
                    <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Background="{TemplateBinding Background}"
                            SnapsToDevicePixels="True"
                            Grid.Row="1">
                        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" 
                                      HorizontalScrollBarVisibility="Hidden" 
                                      VerticalScrollBarVisibility="Hidden"/>
                    </Border>
                </Grid>
            </ControlTemplate>

Я хотел бы знать, почему он не отображается.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...