I have the following Template for my Button
<Window.Resources> <DataTemplate x:Key="ItemTemplate"> <DockPanel Width="Auto"> <Button DockPanel.Dock="Top"> <Button.Template> <ControlTemplate > <Image Source="{Binding image}"/> </ControlTemplate> </Button.Template> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <local:GridLengthAnimation Storyboard.TargetName="col1" Storyboard.TargetProperty="Width" LeftGridWidth="*" RightGridWidth="1*" Duration="0:0:2"/> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> </DockPanel> </DataTemplate> </Window.Resources> <Grid> ... ... <Grid Grid.Row="2" > <Grid.ColumnDefinitions> <ColumnDefinition Name="col1" Width="{Binding ElementName=root, Path=DataContext.gla.LeftGridWidth}" /> <ColumnDefinition Name="col2" Width="{Binding ElementName=root, Path=DataContext.gla.RightGridWidth}" /> </Grid.ColumnDefinitions> <Grid x:Name="LeftGrid" Grid.Row="2" Grid.Column="0" > <Border BorderThickness="1" BorderBrush="Red"> <ItemsControl ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding ElementName=root, Path=DataContext._movies}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="5"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </Border> </Grid> </Grid> </Grid>
The problem is that col1 not col1 Storyboard.TargetName="col1" . I get an error message:
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Additional information: 'col1' name cannot be found in the name scope of 'System.Windows.Controls.Button'.
I think this may be due to the fact that I am using Items Control ... I thought that col1 would try to find in any contained elements. I am not sure how to solve this problem.
Any help would be greatly appreciated!
user2268507
source share