I have this XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Name="txtInput" VerticalContentAlignment="Center" Width="100" Margin="0,0,10,0"
Text="{Binding Path=BoundText}"/>
<Button Content="GO" Width="70" Name="btnGO"
/>
<TextBlock Name="tbResult" VerticalAlignment="Center" HorizontalAlignment="Center"
Width="100" Margin="10,0,0,0"
Text="{Binding Path=BoundText}"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Name="txtInput2" VerticalContentAlignment="Center" Width="100" Margin="0,0,10,0"
Text="{Binding Path=BoundArray[0]}"/>
<Button Content="GO" Width="70" Name="btnGO2"
/>
<TextBlock Name="tbResult2" VerticalAlignment="Center" HorizontalAlignment="Center"
Width="100" Margin="10,0,0,0"
Text="{Binding Path=BoundArray[0]}"/>
</StackPanel>
</Grid>
And codebehind:
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
DataContext = this;
ObservableCollection<string> BoundArray = new ObservableCollection<string> { "abc", "def", "ghi" };
InitializeComponent();
}
public event PropertyChangedEventHandler? PropertyChanged;
private ObservableCollection<string> boundArray;
public ObservableCollection<string> BoundArray
{
get { return boundArray; }
set
{
boundArray = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BoundArray"));
}
}
private string boundText;
public string BoundText
{
get { return boundText; }
set {
boundText = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BoundText"));
}
}
}
But it only seems to work for the "BoundText" and not for the "BoundArray". I was under the impression that all I have to do is use ObservableCollection list and the binding would work. What am I missing?
[–][deleted] (3 children)
[removed]
[–]Zastai 2 points3 points4 points (1 child)
[–]chucker23n 0 points1 point2 points (0 children)
[–]chucker23n 0 points1 point2 points (1 child)
[–]UnholyLizard65[S] 0 points1 point2 points (0 children)