Гость
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Отображение свойства UC / 6 сообщений из 6, страница 1 из 1
10.12.2018, 13:56
    #39745321
Eld Hasp
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
Использую UC для TextBox с подсказкой. Раньше свойство Text в конструкторе отображалось без проблем. Не обратил внимание в какой именно момент, оно в конструкторе перестало отображаться. Увидел это сегодня. Вроде никаких изменений в UC не вносил. По крайней мере не помню такого. Может Студия гонит? ....Или я случайно что-то изменил...
Посмотрите, пожалуйста, как у вас работать будет.
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
<UserControl x:Class="WpfLibrary.TextBoxPromptUC"
             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" 
             xmlns:local="clr-namespace:WpfLibrary"
             mc:Ignorable="d" 
             >
    <Grid>
        <TextBlock x:Name="PART_TextBlock" 
                    Foreground="{Binding DefaultTextBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}" 
                    Margin="5,0" Text="{Binding DefaultText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                    FontStyle="{Binding FontStyle, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                    FontSize="{Binding FontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                    FontFamily="{Binding FontFamily, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                    FontStretch="{Binding FontStretch, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
        />
        <TextBox x:Name="PART_TextBox"     Background="{x:Null}" 
                 Foreground="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}" 
                 FontStyle="{Binding FontStyle, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                 FontSize="{Binding FontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                 FontFamily="{Binding FontFamily, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                 FontStretch="{Binding FontStretch, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"
                 Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}, UpdateSourceTrigger=PropertyChanged}" 
                 TextChanged="PART_TextBox_TextChanged" 
                 BorderBrush="{x:Null}" 
                 IsReadOnly="{Binding ReadOnly, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TextBoxPromptUC}}}"/>

    </Grid>
</UserControl>


Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfLibrary
{
    /// <summary>
    /// Логика взаимодействия для TextBoxPromptUC.xaml
    /// </summary>
    public partial class TextBoxPromptUC : UserControl
    {
        public TextBoxPromptUC()
        {
            InitializeComponent();
        }

        /// <summary>Свойство для цвета текста подсказки</summary>
        public Brush DefaultTextBrush
        {
            get { return (Brush)GetValue(DefaultTextBrushProperty); }
            set { SetValue(DefaultTextBrushProperty, value); }
        }
        public static readonly DependencyProperty DefaultTextBrushProperty =
            DependencyProperty.Register("DefaultTextBrush", typeof(Brush), typeof(TextBoxPromptUC), new PropertyMetadata(SystemColors.InactiveSelectionHighlightBrush));

        /// <summary>Свойство для текста подсказки</summary>
        public string DefaultText
        {
            get { return (string)GetValue(DefaultTextProperty); }
            set { SetValue(DefaultTextProperty, value); }
        }
        public static readonly DependencyProperty DefaultTextProperty =
            DependencyProperty.Register("DefaultText", typeof(string), typeof(TextBoxPromptUC), new PropertyMetadata("Текст по умолчанию - когда пустой TextBox...."));

        /// <summary>Свойство для текста ввода</summary>
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(TextBoxPromptUC), new PropertyMetadata(""));

        /// <summary>Свойство для режима ReadOnly</summary>
        public bool ReadOnly
        {
            get { return (bool)GetValue(ReadOnlyProperty); }
            set { SetValue(ReadOnlyProperty, value); }
        }
        public static readonly DependencyProperty ReadOnlyProperty =
            DependencyProperty.Register("ReadOnly", typeof(bool), typeof(TextBoxPromptUC), new PropertyMetadata(false));

        /// <summary>Обработчик события изменения текста, устанавливающий видимость/невидимость текста подсказки</summary>
        private void PART_TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Text)) PART_TextBlock.Visibility = Visibility.Visible;
            else PART_TextBlock.Visibility = Visibility.Hidden;
        }
    }

}


Проверял просто вставкой текста
Код: xml
1.
2.
3.
    <Grid>
        <wpflib:TextBoxPromptUC Text="12321"/>
    </Grid>

В конструкторе "12321" не отображается, после запуска на исполнение - отображается.
Может какие настройки Студии на это влияют?
...
Рейтинг: 0 / 0
10.12.2018, 14:17
    #39745339
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
конструктор класса всегда выполняется раньше, чем связывание. нельзя из конструктора получить значения связанных свойств зависимостей.
...
Рейтинг: 0 / 0
10.12.2018, 14:27
    #39745359
Eld Hasp
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
Roman Mejtesконструктор класса всегда выполняется раньше, чем связывание. нельзя из конструктора получить значения связанных свойств зависимостей.Я под "Конструктором" имел ввиду Конструктор в редакторе XAML студии.
...
Рейтинг: 0 / 0
10.12.2018, 14:36
    #39745371
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
у меня в группе Misc их видно
...
Рейтинг: 0 / 0
10.12.2018, 16:41
    #39745473
Eld Hasp
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
Roman Mejtesу меня в группе Misc их видноПохоже у меня всё же Студия гонит... или в какие-то настройки залез...
...
Рейтинг: 0 / 0
10.12.2018, 19:44
    #39745598
Eld Hasp
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение свойства UC
Видимо после какого-то из обновлений Конструктор стал работать с багами. Ещё в нескольких местах вылезло неверное отображение элементов в режиме Конструктора. Там где стили, шаблоны задаются в словарях.
...
Рейтинг: 0 / 0
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Отображение свойства UC / 6 сообщений из 6, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]