のプロパティにバインドされていません。依存関係プロパティは、私がIntegerUpDownの実装を持っているViewModelに
public partial class IntegerUpDown
{
public int MaxValue { get; set; } = int.MaxValue;
public int NumValue
{
get { return (int)GetValue(NumValueProperty); }
set { SetValue(NumValueProperty, value); }
}
public static readonly DependencyProperty NumValueProperty =
DependencyProperty.Register("NumValue",
typeof(int), typeof(IntegerUpDown), new PropertyMetadata(0));
public IntegerUpDown()
{
InitializeComponent();
}
//Nothing interesting below
private void cmdUp_Click(object sender, RoutedEventArgs e)
{
if (NumValue < MaxValue)
{
NumValue++;
}
}
private void cmdDown_Click(object sender, RoutedEventArgs e)
{
if (NumValue > 0)
{
NumValue--;
}
}
}
IntegerUpDownとして正常に動作します:
<UserControl x:Class="Scoreboard.View.IntegerUpDown"
...
xmlns:local="clr-namespace:Scoreboard.View"
d:DesignHeight="28" Width="86"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBox x:Name="TxtNum" x:FieldModifier="private" Margin="0,5,0,5" Width="50"
Text="{Binding NumValue,Converter={local:NumberToStringConverter}, Mode=TwoWay}" PreviewTextInput="TxtNum_PreviewTextInput"/>
<!-- Nothing interesting below -->
<Button Margin="0,5" x:Name="CmdUp" x:FieldModifier="private" Width="18" Click="cmdUp_Click" >
<Path Data="M 0,300 L 0,300 200,0 400,300" Stretch="Fill" Width="8.333" Height="5.833" Stroke="Black"/>
</Button>
<Button Margin="0,5" x:Name="CmdDown" x:FieldModifier="private" Width="18" Click="cmdDown_Click" >
<Path Data="M 0,-300 L 0,-300 -200,0 -400,-300" Stretch="Fill" Width="8.333" Height="5.833" Stroke="Black"/>
</Button>
</StackPanel>
</Grid>
と背後にあるコードスタンドアロンTextBoxのテキストはDP NumValueと同じです。問題は、このコントロールが別のコントロールによって使用され、NumValueを別のプロパティでバインドする場合です。この
<UserControl x:Class="Scoreboard.View.TeamGameControl"
...
d:DataContext="{d:DesignInstance ViewModel:ControlPanel}">
<local:IntegerUpDown ... NumValue="{Binding Val, Mode=TwoWay}"/>
<!-- doesn't do anything ↑ ... why? -->
そして、どのように同様のDataContextプロパティにヴァルに見える2つのプロパティ(ヴァル、NumValue)の
public class ControlPanel : INotifyPropertyChanged {
public int Val
{
get { return _val; }
set
{
_val = value;
RaisePropertyChangedEvent("Val");
}
}
}
どれがこれまでに更新されません。私は間違って何をしていますか?
編集: 必要な部分を削除しました。ここではprojectです。
のようなテキストボックスのテキストをバインドVal、Mode = TwoWay} " –
私はこの質問を書いていたときに間違いを犯しました。今すぐ編集されます。しかし、私の問題は解決しません。 – Korhak
バインディングを変更しましたか? –