【问题标题】:Change width of an element in an usercontrol to the width of an element in another usercontrol using storyboard使用情节提要将用户控件中元素的宽度更改为另一个用户控件中元素的宽度
【发布时间】:2019-03-14 16:28:30
【问题描述】:

我想将 Usercontrol1 中“GridMenu”的宽度设置为 MainWindow 中 Grid.Column (0) 的 ActualWidth。

用户控件 1:

    <Usercontrol...> 
<Usercontrol.Resources>          
     <Storyboard x:Key="OpenMenu">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
                    <EasingDoubleKeyFrame KeyTime="0" Value="30"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="thisValueIWantToBind"/>
                </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Usercontrol.Resources> 

         <Grid x:Name="GridMenu" HorizontalAlignment="Left" Width="30" Background="LightBlue"/>
    </Usercontrol>

主窗口:

 <Grid Grid.Row="1" Background="Beige">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition Width="3*"/>
            </Grid.ColumnDefinitions>

            <local:usercontrol1 Grid.Column="0"/>
</Grid>

【问题讨论】:

    标签: c# wpf xaml binding storyboard


    【解决方案1】:

    您可以在后面的代码中编写情节提要,以便您可以轻松地从用户控件访问 MainWindow。只是猜测。

    【讨论】:

    • 我想过,但我想用 XAML 来做。
    【解决方案2】:

    您可以在 usercontrol1 中创建一个依赖属性,例如 Column1Width。 在 MainWindow 中,为第一列命名。 还,

    然后在 usercontrol1 中,

    【讨论】:

      猜你喜欢
      • 2019-06-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 2017-12-31
      • 2018-01-29
      • 2018-10-15
      • 1970-01-01
      • 2020-08-10
      相关资源
      最近更新 更多