我有两个用户控件:
Usercontrol 1:
- 在名为" somestoryboard"。的用户控制资源中包含故事板动画
- 包含一个键盘,当有人点击usercontrol 2中的文本框时,该键盘必须向上滑动
- 包含任何usercontrol动态驻留的contentcontrol。
Usercontrol 2:
- 包含带有eventtrigger的文本框。触摸时,必须触发来自usercontrol 1的故事板。
不幸的是,整个绑定在第二个用户控件中出错了。我经常收到消息"无法找到故事板的对象"。
如何在usercontrol 2中设置此绑定,或者甚至可以在纯xaml中设置此绑定?
以下是两个用户控件:
Usercontrol 1:
<UserControl (some namespaces)>
<UserControl.Resources>
<Storyboard x:Key="SomeControl">
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="aControl"
Storyboard.TargetProperty="Expanded" >
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="500" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="800" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="1" Grid.Row="1" Background="{StaticResource DefaultBackground}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition />
<RowDefinition Height="70" />
</Grid.RowDefinitions>
<ContentControl Grid.Row="1" Grid.Column="2" Margin="10,0,20,0" VerticalContentAlignment="Top"/>
</Grid>
<Controls:Somecontrol x:Name="aControl" VerticalAlignment="Bottom" Height="0" HorizontalAlignment="Stretch"
Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Grid.RowSpan="2" UseAnimation="True"
Style="{StaticResource AnimatedControl}" />
</Grid>
Usercontrol 2:
<UserControl (some namespaces)>
<Grid Margin="5" >
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding InputMessage}" VerticalAlignment="Center" FontSize="12" Margin="0,0,0,5" />
<TextBox Grid.Row="1" Text="{Binding InputResult}" InnerBorderBrush="Blue" CornerRadius="5" Background="White" >
<TextBox .Triggers>
<EventTrigger RoutedEvent="TextBox.TouchUp">
<BeginStoryboard Storyboard="{StaticResource SomeControl}" />
</EventTrigger>
</TextBox.Triggers>
</TextBlock >
</Grid>
</UserControl>