Bindings: fix command lookup in DataTemplates by scoping Button.DataContext to root VM and using Tag to preserve item context; set CommandParameter via Tag.
This commit is contained in:
parent
1667fc8b3d
commit
fa6a24ea30
1 changed files with 36 additions and 30 deletions
|
@ -36,13 +36,16 @@
|
||||||
AutomationProperties.Name="Variables list">
|
AutomationProperties.Name="Variables list">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate x:DataType="m:VariableItem">
|
<DataTemplate x:DataType="m:VariableItem">
|
||||||
<Button Command="{Binding $parent[UserControl].DataContext.InsertVariableCommand}"
|
<Button Background="Transparent" BorderThickness="0" Padding="8" MinHeight="44"
|
||||||
CommandParameter="{Binding VariableName}"
|
AutomationProperties.Name="Insert variable"
|
||||||
Background="Transparent" BorderThickness="0" Padding="8" MinHeight="44"
|
Tag="{Binding}"
|
||||||
AutomationProperties.Name="Insert variable">
|
DataContext="{Binding $parent[UserControl].DataContext}"
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
Command="{Binding InsertVariableCommand}"
|
||||||
<TextBlock Grid.Column="0" FontFamily="{StaticResource MDI}"
|
CommandParameter="{Binding Tag.VariableName, RelativeSource={RelativeSource Self}}">
|
||||||
FontSize="{DynamicResource IconSizeM}" Text="{Binding Icon}" VerticalAlignment="Center" Margin="0,0,8,0" />
|
<Grid ColumnDefinitions="Auto,*,Auto"
|
||||||
|
DataContext="{Binding Tag, RelativeSource={RelativeSource AncestorType=Button}}">
|
||||||
|
<TextBlock Grid.Column="0" FontFamily="{StaticResource MDI}"
|
||||||
|
FontSize="{DynamicResource IconSizeM}" Text="{Binding Icon}" VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||||
<TextBlock Grid.Column="1" Text="{Binding VariableName}" FontWeight="Bold" VerticalAlignment="Center" />
|
<TextBlock Grid.Column="1" Text="{Binding VariableName}" FontWeight="Bold" VerticalAlignment="Center" />
|
||||||
<StackPanel Grid.Column="2" Spacing="6" VerticalAlignment="Center">
|
<StackPanel Grid.Column="2" Spacing="6" VerticalAlignment="Center">
|
||||||
<TextBlock Text="{Binding Value}" />
|
<TextBlock Text="{Binding Value}" />
|
||||||
|
@ -65,30 +68,33 @@
|
||||||
ItemsSource="{x:Static m:FunctionDefinitionItem.DefinedFunctions}"
|
ItemsSource="{x:Static m:FunctionDefinitionItem.DefinedFunctions}"
|
||||||
AutomationProperties.Name="Functions list">
|
AutomationProperties.Name="Functions list">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate x:DataType="m:FunctionDefinitionItem">
|
<DataTemplate x:DataType="m:FunctionDefinitionItem">
|
||||||
<Button Command="{Binding $parent[UserControl].DataContext.InsertFunctionCommand}"
|
<Button Background="Transparent" BorderThickness="0" Padding="8" MinHeight="44"
|
||||||
CommandParameter="{Binding FunctionName}"
|
AutomationProperties.Name="Insert function"
|
||||||
Background="Transparent" BorderThickness="0" Padding="8" MinHeight="44"
|
Tag="{Binding}"
|
||||||
AutomationProperties.Name="Insert function">
|
DataContext="{Binding $parent[UserControl].DataContext}"
|
||||||
<StackPanel Spacing="8">
|
Command="{Binding InsertFunctionCommand}"
|
||||||
<StackPanel Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
|
CommandParameter="{Binding Tag.FunctionName, RelativeSource={RelativeSource Self}}">
|
||||||
<TextBlock FontFamily="{StaticResource MDI}" Text="{Binding Icon}" />
|
<StackPanel Spacing="8"
|
||||||
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold" />
|
DataContext="{Binding Tag, RelativeSource={RelativeSource AncestorType=Button}}">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
|
||||||
|
<TextBlock FontFamily="{StaticResource MDI}" Text="{Binding Icon}" />
|
||||||
|
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold" />
|
||||||
|
</StackPanel>
|
||||||
|
<TextBlock Text="{Binding FunctionDescription}" FontStyle="Italic" TextWrapping="Wrap" />
|
||||||
|
<ItemsControl ItemsSource="{Binding FunctionArguments}">
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="{Binding Key}" />
|
||||||
|
<TextBlock Text="{Binding Value}" FontStyle="Italic" Margin="8,0,0,0" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<TextBlock Text="{Binding FunctionDescription}" FontStyle="Italic" TextWrapping="Wrap" />
|
</Button>
|
||||||
<ItemsControl ItemsSource="{Binding FunctionArguments}">
|
</DataTemplate>
|
||||||
<ItemsControl.ItemTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<StackPanel>
|
|
||||||
<TextBlock Text="{Binding Key}" />
|
|
||||||
<TextBlock Text="{Binding Value}" FontStyle="Italic" Margin="8,0,0,0" />
|
|
||||||
</StackPanel>
|
|
||||||
</DataTemplate>
|
|
||||||
</ItemsControl.ItemTemplate>
|
|
||||||
</ItemsControl>
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
</DataTemplate>
|
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue