• silverlight中TimePicker和TimeUpdown无法在ChildWindow中使用的问题


    silverlight存在一个bug,那就是popup无法嵌套的问题,childwindow是一个popup,timepicker和timeupdown定义中也存在一个popup,即下图的效果:

    我在网上(http://forums.silverlight.net/forums/p/108539/297083.aspx)找到的解决办法就是重写timeupdown的style,将popup关掉即可实现在childwindow中添加timeupdown了,我只找到了timeupdown的style定义,以下是我重写后的style:

    <Style x:Key="TimePicker_IsPopupFalse"
    TargetType="inputToolkit:TimeUpDown">
    
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="MinHeight" Value="20" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="MinWidth" Value="20" />
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9" Offset="0" />
                        <GradientStop Color="#FF8399A9" Offset="0.375" />
                        <GradientStop Color="#FF718597" Offset="0.375" />
                        <GradientStop Color="#FF617584" Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="inputToolkit:TimeUpDown">
                        <Grid>
                            <!-- visual states -->
                            <vsm:VisualStateManager.VisualStateGroups>
                                <!-- common states-->
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <!-- all contained elements are controls that will take care of visualizing the disabled state themselves -->
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver" />
                                    <vsm:VisualState x:Name="Pressed" />
                                    <vsm:VisualState x:Name="Disabled" />
                                </vsm:VisualStateGroup>
                                <!-- focus states -->
                                <vsm:VisualStateGroup x:Name="FocusStates">
                                    <!-- all contained elements are controls that will take care of visualizing the focus state themselves -->
                                    <vsm:VisualState x:Name="Focused" />
                                    <vsm:VisualState x:Name="Unfocused" />
                                </vsm:VisualStateGroup>
                                <!-- TimeHintStates -->
                                <vsm:VisualStateGroup x:Name="TimeHintStates">
                                    <vsm:VisualState x:Name="TimeHintOpenedUp">
                                        <Storyboard>
                                            <!--lensso修改【注释部分为样式定义】-->
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintPopup" Storyboard.TargetProperty="IsOpen">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="True"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <!--<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Visibility">
    <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
    </ObjectAnimationUsingKeyFrames>-->
                                            <!--/lensso修改-->
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
    
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="-23" />
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Height">
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="22" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="TimeHintOpenedDown">
                                        <Storyboard>
                                            <!--lensso修改【注释部分为原样式定义】-->
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintPopup" Storyboard.TargetProperty="IsOpen">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="True"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <!--<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Visibility">
    <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
    </ObjectAnimationUsingKeyFrames>-->
                                            <!--/lensso修改-->
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="0" />
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Height">
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="22" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="TimeHintClosed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:20" Value="Collapsed" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="0" />
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TimeHintVisualElement" Storyboard.TargetProperty="Height">
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="22" />
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.200" KeySpline="0,0,0,1" Value="0" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                                <!-- ParsingStates -->
                                <vsm:VisualStateGroup x:Name="ParsingStates">
                                    <vsm:VisualState x:Name="ValidTime">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="validicon" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="InvalidTime">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="invalidicon" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="EmptyTime">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="emptyicon" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <!-- Spinner + HintVisualElement + TextBox -->
                            <!-- the border will be 'flown out' to act as a balloon -->
                            <!--lensso修改【原样式定义为IsOpen="True"】-->
                            <Popup x:Name="TimeHintPopup" IsOpen="False" VerticalOffset="0">
                                <!--/lensso修改-->
                                <Border x:Name="TimeHintVisualElement" IsHitTestVisible="True" BorderBrush="Gray" Background="White" Visibility="Collapsed"  HorizontalAlignment="Left" BorderThickness="1">
                                    <Border.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform />
                                        </TransformGroup>
                                    </Border.RenderTransform>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" MinWidth="15" />
                                        </Grid.ColumnDefinitions>
                                        <ContentControl Grid.Column="0" IsTabStop="False" IsHitTestVisible="False" Margin="3" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="#FF4A4A4A" FontSize="10" Content="{TemplateBinding TimeHintContent}" />
                                        <ContentControl x:Name="emptyicon" IsTabStop="False" IsHitTestVisible="False" Margin="3" Visibility="Collapsed" Grid.Column="1" />
                                        <ContentControl x:Name="validicon" IsHitTestVisible="False" IsTabStop="False" Margin="3" Visibility="Collapsed" Grid.Column="1" />
                                        <ContentControl x:Name="invalidicon" IsTabStop="False" IsHitTestVisible="False" Visibility="Collapsed" VerticalAlignment="Center" Grid.Column="1">
                                            <Grid VerticalAlignment="Bottom" Width="10" Height="13">
                                                <Path Stretch="Fill" Data="F1 M 28.1143,29.4857L 28.1143,27.4286L 20.7612,13.0286L 19.3898,13.0286L 12.3429,27.4286L 12.3429,29.4857L 28.1143,29.4857 Z " StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Bevel" Height="11.833" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                                                    <Path.Stroke>
                                                        <LinearGradientBrush StartPoint="1.10074,0.462591" EndPoint="-0.102151,0.462591">
                                                            <GradientStop Color="#F6CAA709" Offset="0.0436364" />
                                                            <GradientStop Color="#F3F7F34F" Offset="0.149091" />
                                                            <GradientStop Color="#E7CAA709" Offset="0.825455" />
                                                            <GradientStop Color="#E7967C07" Offset="0.967124" />
                                                            <GradientStop Color="#E7625106" Offset="0.967273" />
                                                        </LinearGradientBrush>
                                                    </Path.Stroke>
                                                    <Path.Fill>
                                                        <LinearGradientBrush StartPoint="1.13883,0.460318" EndPoint="-0.140331,0.460318">
                                                            <GradientStop Color="#FFF7F79F" Offset="0.123636" />
                                                            <GradientStop  Color="#FBFBFB7D" Offset="0.177662" />
                                                            <GradientStop Color="#F6FFFF5B" Offset="0.24" />
                                                            <GradientStop Color="#E7CAA709" Offset="0.52" />
                                                            <GradientStop Color="#9ADABE0C" Offset="0.941376" />
                                                            <GradientStop Color="#4DEBD60F" Offset="0.941818" />
                                                            <GradientStop Color="#FBF6EC20" Offset="0.956364" />
                                                            <GradientStop Color="#FFFFFF2F" Offset="0.963636" />
                                                        </LinearGradientBrush>
                                                    </Path.Fill>
                                                </Path>
                                                <Path Stretch="Fill" StrokeThickness="0.3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Bevel" Stroke="#FF1B1B54" Data="F1 M 18.6937,17.3004L 22.2563,17.3004L 21.1313,23.6937L 19.8563,23.6937L 18.6937,17.3004 Z " Margin="4.25,2.25,3.75,0" Height="4.683" VerticalAlignment="Top">
                                                    <Path.Fill>
                                                        <LinearGradientBrush StartPoint="-0.400002,0.50126" EndPoint="1.4,0.50126">
                                                            <GradientStop Color="#FFF7F79F" Offset="0.123636" />
                                                            <GradientStop Color="#FB8F8873" Offset="0.175974" />
                                                            <GradientStop Color="#F6271A47" Offset="0.236364" />
                                                            <GradientStop Color="#E7271A47" Offset="0.534545" />
                                                            <GradientStop Color="#9A89782B" Offset="0.941391" />
                                                            <GradientStop Color="#4DEBD60F" Offset="0.941818" />
                                                            <GradientStop Color="#FBF6EC20" Offset="0.956364" />
                                                            <GradientStop Color="#FFFFFF2F" Offset="0.963636" />
                                                        </LinearGradientBrush>
                                                    </Path.Fill>
                                                </Path>
                                                <Path Height="3.11" Stretch="Fill" StrokeThickness="0.3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Stroke="#FF1C1C50" Data="F1 M 20.225,25.122L 20.725,25.122C 21.2773,25.122 21.725,25.5697 21.725,26.122L 21.725,26.872C 21.725,27.4243 21.2773,27.872 20.725,27.872L 20.225,27.872C 19.6727,27.872 19.225,27.4243 19.225,26.872L 19.225,26.122C 19.225,25.5697 19.6727,25.122 20.225,25.122 Z " Margin="3.833,0,4.167,0.833" VerticalAlignment="Bottom">
                                                    <Path.Fill>
                                                        <LinearGradientBrush StartPoint="-0.0599991,0.5" EndPoint="1.06,0.5">
                                                            <GradientStop Color="#F6271A47" Offset="0.236364" />
                                                            <GradientStop Color="#E7271A47" Offset="0.534545" />
                                                            <GradientStop Color="#9A89782B" Offset="0.98135" />
                                                            <GradientStop Color="#4DEBD60F" Offset="0.981818" />
                                                        </LinearGradientBrush>
                                                    </Path.Fill>
                                                </Path>
                                            </Grid>
                                        </ContentControl>
                                    </Grid>
                                </Border>
                            </Popup>
                            <inputToolkit:ButtonSpinner x:Name="Spinner" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Style="{TemplateBinding SpinnerStyle}" MinWidth="35" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" IsTabStop="False">
                                <TextBox x:Name="Text" BorderThickness="0" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" MinWidth="20" AcceptsReturn="False" Text="{TemplateBinding Value}" TextAlignment="Right" TextWrapping="NoWrap">
                                    <TextBox.Style>
                                        <Style TargetType="TextBox">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="TextBox">
                                                        <ScrollViewer x:Name="ContentElement" Padding="0" BorderThickness="0" />
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </TextBox.Style>
                                </TextBox>
                            </inputToolkit:ButtonSpinner>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

    <!--lensso修改--><!--/lensso修改-->之间的部分是我做过修改的部分。

    完成以上style重写以后在添加timeupdown时将它的style设成重写的style,如下:
     <inputToolkit:TimeUpDown Height="25" Width="20" Style="{StaticResource TimePicker_IsPopupFalse}"/>

    完成以上所有工作后在childwindow中打开的页面就可以正常使用timeupdown控件了。


  • 相关阅读:
    MySQL InnoDB事务隔离级别脏读、可重复读、幻读
    数据结构与算法-Python/C
    Go语言 转至Nick老师博客
    短信验证功能、邮箱验证功能
    psutil模块
    简单邮件传输协议SMTP
    CSS3主要的几个样式笔记
    cURL的几个经典实例
    Socket进程通信机制
    对PDO的认识
  • 原文地址:https://www.cnblogs.com/larson/p/2014428.html
Copyright © 2020-2023  润新知