의 속성에 바인딩하지 않습니다종속성 속성은 내가 IntegerUpDown의 구현이 뷰 모델
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에 재산 발을 보이는 : 두 개의 속성 (발, NumValue)의
public class ControlPanel : INotifyPropertyChanged {
public int Val
{
get { return _val; }
set
{
_val = value;
RaisePropertyChangedEvent("Val");
}
}
}
누구도 업데이트되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
편집 : 필요한 부분을 잘라 냈습니다. 여기는 project입니다.
같은 텍스트 상자의 텍스트를 결합 Val, Mode = TwoWay} " –
이 질문을 쓸 때 실수를했습니다. 이제 편집됩니다. 동등하지 않은 내 문제를 해결하지 않지만. – Korhak
바인딩을 변경 했습니까? –