1

ヘッダーの説明をもう少しうまくできるかもしれません。

これがシナリオです。

DependencyObject から継承するクラス RecordNavigationDescriptor を取得しました。内部には依存関係プロパティがあり、このスコープでは「MyObject」と呼びます。

このオブジェクトをユーザー コントロールのタグ プロパティに割り当てたいと思います。「MyObject」dp がユーザー コントロールのコントロールの 1 つを指すようにします。

<UserControl x:Class="ucTest"
         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:local="clr-namespace:Exchange"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Name="MyTextBlock" FontSize="72" FontWeight="ExtraBold" Text="Testing...."/>
        <Button VerticalAlignment="Bottom" Click="Button_Click">Click Me</Button>
        <Grid.Tag>
            <local:RecordNavigationDescriptor MyObject="{Binding ElementName=MyTextBlock}"  FriendlyName="Testing... Testing..."/>
        </Grid.Tag>
    </Grid>
</UserControl>

このバインディングは機能しません。したがって、「MyObject」は Null になります。

でも、

<UserControl x:Class="ucTest"
         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:local="clr-namespace:Exchange"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Name="MyTextBlock" FontSize="72" FontWeight="ExtraBold" Text="Testing...."/>
        <Button VerticalAlignment="Bottom" Click="Button_Click">Click Me</Button>
        <local:RecordNavigationDescriptor MyObject="{Binding ElementName=MyTextBlock}" FriendlyName="Testing... Testing..."/>
    </Grid>
</UserControl>

これは機能します。

それで、問題の原因は何ですか?

RecordNavigationDescriptor オブジェクトを静的リソースとしてインスタンス化する必要がありますか? それをTagプロパティに割り当てますか?

4

0 に答える 0