Как я могу получить доступ к значениям DependencyProperty из своего кода - позади конструктора?

Используйте getActionBar().setDisplayHomeAsUpEnabled(false) для удаления кнопки «Домой» с панели действий.

5
задан Giffyguy 26 July 2009 в 17:34
поделиться

3 ответа

<local:SmartForm Status="Ready"/>

Преобразуется как:

SmartForm f = new SmartForm();
f.Status = Status.Ready;

У вас будет доступ к этому значению при вызове установщика.

3
ответ дан 14 December 2019 в 13:45
поделиться

Вы можете установить это тестовое сообщение как:

...
    public static readonly DependencyProperty StatusProperty = 
        DependencyProperty.Register("Status", typeof(string), typeof(SmartForm),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.None,
            new PropertyChangedCallback(OnStatusChanged)));

    public static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        ((SmartForm)d).TestingMessage.Text = e.NewValue.ToString();
    }
...

или как:

<UserControl 
x:Class="TestPropertyDefine23282.SmartForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestPropertyDefine23282"
Height="300" Width="300"
>
<Grid>
    <TextBlock
        x:Name="TestingMessage"
        Text="{Binding Path=Status, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:SmartForm}}}"
        />
</Grid>
</UserControl>
3
ответ дан 14 December 2019 в 13:45
поделиться

Это вроде как третичный, но зачем вам вообще этот сеттер?

<UserControl x:Class="TestPropertyDefine23282.SmartForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="Control"
    Height="300" Width="300">
    <Grid>
        <TextBlock Text="{Binding Path=Status, ElementName=Control}" />
    </Grid>
</UserControl>
-1
ответ дан 14 December 2019 в 13:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: