0

私はコンパイルされたデータ バインディング (x:bind) について知りました。パフォーマンス、xaml ページのコンパイル時エラー、バインディング イベントなど、多くの利点があります。コンパイル済みデータ バインディングに関するチュートリアルの 1 つを実行すると、オブジェクトを動的にバインドするシナリオでは x:bind を使用できないことが明確に示されています。特に x:bind を使用して解決できないランタイム バインディングの例を探しています。動的オブジェクト バインディングを使用した小さなコードは、非常に高く評価されます。前もって感謝します

4

1 に答える 1

0

特定のプロパティが存在するかどうかわからない場合は、通常 Binding を使用します。例:

<DataTemplate x:DataType="Message">
    <StackPanel>
        <TextBlock Text="{x:Bind Title}" />
        // if binding fails, the value is set to 0
        <ProgressBar Value="{Binding Progress, FallbackValue=0}"
                     Maximum="1"
                     Background="Transparent" />
    </StackPanel>
</DataTemplate>
public class Message
{
    public string Title { get; set; }
}

public class MessageWithProgress : Message
{
    public double Progress { get; set; }
}

それでも、この例ではDataTemplateSelectorを使用して Binding の使用を避けることができます。

于 2020-05-07T22:14:11.027 に答える