У меня проблема с обновлением привязки к свойству в моем объекте. при запуске он показывает прекрасный результат, но после редактирования источника значение не обновляется в моем окне.Свойство привязки WPF не обновляется при обновлении
public class Marker : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
private ObservableCollection<bool?> _repeat;
[...]
public ObservableCollection<bool?> Repeat
{
get { return _repeat; }
set
{
_repeat = value;
OnPropertyChanged(new PropertyChangedEventArgs("Repeat"));
OnPropertyChanged(new PropertyChangedEventArgs("RepeatString"));
}
}
[...]
[XmlIgnore]
public string RepeatString
{
get
{
string wt = string.Empty;
wt += (bool)Repeat[0] ? "Mo, " : string.Empty;
wt += (bool)Repeat[1] ? "Di, " : string.Empty;
wt += (bool)Repeat[2] ? "Mi, " : string.Empty;
wt += (bool)Repeat[3] ? "Do, " : string.Empty;
wt += (bool)Repeat[4] ? "Fr, " : string.Empty;
wt += (bool)Repeat[5] ? "Sa, " : string.Empty;
wt += (bool)Repeat[6] ? "So, " : string.Empty;
if (wt != string.Empty)
{
wt = wt.Remove(wt.Length - 2);
}
return wt;
}
[...]
}
[...]
}
В XAML части я установил привязок следующим образом:
<Grid DataContext="{Binding ElementName=lvMarker, Path=SelectedItem}">
[...]
<CheckBox Content="Montag" IsChecked="{Binding Repeat[0], Mode=TwoWay}"/>
<CheckBox Content="Dienstag" IsChecked="{Binding Repeat[1], Mode=TwoWay}"/>
<CheckBox Content="Mittwoch" IsChecked="{Binding Repeat[2], Mode=TwoWay}"/>
<CheckBox Content="Donnerstag" IsChecked="{Binding Repeat[3], Mode=TwoWay}"/>
<CheckBox Content="Freitag" IsChecked="{Binding Repeat[4], Mode=TwoWay}"/>
<CheckBox Content="Samstag" IsChecked="{Binding Repeat[5], Mode=TwoWay}"/>
<CheckBox Content="Sonntag" IsChecked="{Binding Repeat[6], Mode=TwoWay}"/>
</StackPanel>
</Grid>
это обновление массива просто отлично, как я щелкая на поле. но не привязка к текстовому блоку.
<ListView x:Name="lvMarker" ItemsSource="{Binding MarkerCollection}" Width="Auto" ItemContainerStyle="{StaticResource lvItemStyle}">
<ListView.View>
<GridView>
[...]
<GridViewColumn Header="Zeit" Width="Auto" CellTemplate="{StaticResource DateCell}"/>
</GridView>
</ListView.View>
</ListView>
...
<DataTemplate x:Key="DateCell">
<StackPanel>
<TextBlock FontSize="14">
[...]
</TextBlock>
<TextBlock FontSize="10" Text="{Binding RepeatString, Mode=OneWay}"/>
</StackPanel>
</DataTemplate>
Что я должен сделать, чтобы обновить TextBlock, представляющий RepeatString, когда я изменить логическое значение? повторения []?
спасибо, что выполнило эту работу. Короткие и простые – chrosey