UserControlの依存関係プロパティのバインドに問題があります。初期化すると値を取得しますが、更新されません。私はおそらく明らかな何かを見逃しました、ここにいくつかのコードスニペットがあります:
BalanceContent
これは、依存関係プロパティをバインドする場所です。
<Game:PlayerDetails x:Name="SelectedPlayerDetails" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Grid.RowSpan="4"
BalanceContent="{Binding Source={StaticResource UserData}, Path=SelectedUser.Balance, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
</Game:PlayerDetails>
これが:TextBox
にありUserControl
ます
<TextBox VerticalAlignment="Center" FontFamily="Formata" FontSize="20" Grid.Column="2"
Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}, Path=BalanceContent}"
Grid.Row="7"></TextBox>
依存関係プロパティは次のとおりです。
public static readonly DependencyProperty BalanceContentProperty = DependencyProperty.Register(
"BalanceContent", typeof(string), typeof(PlayerDetails));
public string BalanceContent
{
get
{return (string) GetValue(BalanceContentProperty);}
set
{SetValue(BalanceContentProperty, value);}
}
選択したユーザーが更新されるリストは次のとおりです。これは、UserControlを使用するビューにあります。
<ListView x:Name="lstAccounts" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Grid.RowSpan="4"
ItemsSource="{Binding Source={StaticResource UserData}, Path=CurrentUserSearch}"
SelectedItem="{Binding Source={StaticResource UserData}, Path=SelectedUser}"
そしてSelectedUser
、ここで実装するクラスで定義されていますINotifyPropertyChanged
:
public User SelectedUser
{
get
{
return _selectedUser;
}
set
{
_selectedUser = value;
OnPropertyChanged(new PropertyChangedEventArgs("SelectedUser"));
}
}
アイデアは、リストで新しいユーザーが選択されたときにTextBoxを更新する必要があるということですが、現時点では更新されていません。バインディングをローカルのTextBoxに配置しましたが、ではなく正常に更新されますDependencyProperty
。助けていただければ幸いです。