【WPF】wpf笔记本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/catshitone/article/details/72681761

1.对于ListView、ListBox等这些派生自ItemsControl的类,它们的子item的button之类的控件如何绑定到父page或者父window的ViewModel上?

Command="{Binding DataContext.BackupCommand,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Page}}}"
如果父布局是window,则将x:Type Page改为x:Type Windows.


2.ListBox中的Item当被遮挡了一部分时,点击此item后会先把位置往上移,再次点击才执行相应操作,会让用户误以为一次点击没有效果,需要点击两次。

解决方法是:将ListBox的style中的ScrollView的CanContentScroll属性的值设置为false。

3.带Hint的TextBox控件

设置TextBox控件的Template属性为:

    <ControlTemplate x:Key="HintTextBoxControlTemplate" TargetType="{x:Type TextBoxBase}">
        <Border CornerRadius="10" x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
            <Grid>
                <TextBlock x:Name="hint" Foreground="LightGray" Margin="10"  Text="{TemplateBinding Tag}"></TextBlock>
                <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>

            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Opacity" TargetName="hint" Value="0"/>
            </Trigger>

        </ControlTemplate.Triggers>
    </ControlTemplate>

把Hint的文字,写在对应的TextBox的Tag标签中。


4.控件选中时设置以控件中心为旋转点

<Image RenderTransformOrigin="0.5,0.5" 


猜你喜欢

转载自blog.csdn.net/catshitone/article/details/72681761
WPF