main
syneffort 2 years ago
parent 2d19b48778
commit 8fe7d30387
  1. 8
      PacticeSolution/MVVMButtonControl/MainWindow.xaml
  2. 2
      PacticeSolution/MVVMButtonControl/ViewModel/ModelViewMain.cs

@ -12,18 +12,18 @@
</Window.DataContext> </Window.DataContext>
<StackPanel> <StackPanel>
<Button Content="Add TextBox" Command="{Binding TestCommand}"/> <Button x:Name="btnMain" Content="Add TextBox" Command="{Binding TestCommand}"/>
<ItemsControl x:Name="itcMain" ItemsSource="{Binding ButtonCollection}"> <ItemsControl x:Name="ctrMain" ItemsSource="{Binding ButtonCollection}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Button x:Name="btnItem" <Button x:Name="btnSub"
Content="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Content="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
FontWeight="Bold" FontWeight="Bold"
FontSize="18" FontSize="18"
Margin="10" Margin="10"
Width="100" Width="100"
Background="{Binding SelectedColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Background="{Binding SelectedColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Command="{Binding ElementName=itcMain, Path=SubCommandMethod}" Command="{Binding ElementName=ctrMain, Path=DataContext.SubButtonCommand}"
CommandParameter="{Binding Name}"/> CommandParameter="{Binding Name}"/>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>

@ -52,7 +52,7 @@ namespace MVVMButtonControl.ViewModel
this.ButtonCollection[i].SelectedColor = Brushes.Transparent; this.ButtonCollection[i].SelectedColor = Brushes.Transparent;
} }
Buttons selected = this.ButtonCollection.Where(b => b.Name.Equals(parameter.ToString())).SingleOrDefault(); Buttons? selected = this.ButtonCollection.Where(b => b.Name.Equals(parameter.ToString())).SingleOrDefault();
if (selected == null) if (selected == null)
return; return;

Loading…
Cancel
Save