小编Tim*_*ens的帖子

使用反射c#将动态对象转换为类型

请考虑以下代码

 var currentType = Type.GetType("Some.Type, Some");
 dynamic myDynamic = new System.Dynamic.ExpandoObject();
 myDynamic.A = "A";
 var objectInCorrectType = ???
Run Code Online (Sandbox Code Playgroud)

如何将动态转换为currentType?

c# reflection

10
推荐指数
2
解决办法
7640
查看次数

WPF:无法在样式的目标标签上指定事件“已完成”。改用EventSetter

我正在尝试在故事板完成后运行一些代码,但似乎找不到如何设置的代码...

Completed="LoadingStoryBoard_Completed"
Run Code Online (Sandbox Code Playgroud)

在情节提要元素上,我收到错误消息“无法在样式的目标标签上指定事件'已完成'。请改用EventSetter。” 但是,很难找到有关如何使用事件设置器的良好参考。

Xaml代码如下所示(其结构如下:当图像可见时,它可以启动)

<Window.Resources>
    <Style x:Key="AnimationImageStyle" TargetType="{x:Type Image}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsVisible}" 
             Value="True">

                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard Name="LoadingStoryBoard"  >

                            <!-- -->
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source"
                                               Duration="0:0:4">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <BitmapImage UriSource="C:\...\2a-loading.jpg"/>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:1">
                                    <DiscreteObjectKeyFrame.Value>
                                        <BitmapImage UriSource="C:\...\2b-loading.jpg"/>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:2">
                                    <DiscreteObjectKeyFrame.Value>
                                        <BitmapImage UriSource="C:\...\2c-loading.jpg"/>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:3">
                                    <DiscreteObjectKeyFrame.Value>
                                        <BitmapImage UriSource="C:\...\2d-loading.jpg"/>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>


<Grid Name="GridLoading" Visibility="Hidden" >

        <Image Style="{StaticResource AnimationImageStyle}" >
        </Image>

</Grid>
Run Code Online (Sandbox Code Playgroud)

所有提示大加赞赏

c# wpf xaml

6
推荐指数
1
解决办法
983
查看次数

标签 统计

c# ×2

reflection ×1

wpf ×1

xaml ×1