• WPF Tips


    GridSplitter

    <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    
    <GridSplitter Grid.Column="1" HorizontalAlignment="Center" Width="5" />

    Accordian

    <StackPanel>
                <StackPanel.Resources>
                    <local:ExpanderToBooleanConverter x:Key="ExpanderToBooleanConverter" />
                </StackPanel.Resources>
                <Expander Header="Expander 1" IsExpanded="{Binding ExpanderIndex, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=0}">
                    <Grid Margin="24,8">
                        <TextBlock Text="Content 1" />
                    </Grid>
                </Expander>
                <Expander Header="Expander 2" IsExpanded="{Binding ExpanderIndex, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=1}">
                    <Grid Margin="24,8">
                        <TextBlock Text="Content 2" />
                    </Grid>
                </Expander>
                <Expander Header="Expander 3" IsExpanded="{Binding ExpanderIndex, Mode=TwoWay, Converter={StaticResource ExpanderToBooleanConverter}, ConverterParameter=2}">
                    <Grid Margin="24,8">
                        <TextBlock Text="Content 3" />
                    </Grid>
                </Expander>
            </StackPanel>
    private int _expanderIndex;
    
            public int ExpanderIndex
            {
                get { return _expanderIndex; }
                set { SetProperty(ref _expanderIndex, value); }
            }
    
        public class ExpanderToBooleanConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return (value.ToString() == (string)parameter);
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return System.Convert.ToBoolean(value) ? parameter : null;
            }
        }

    AutoSize ListBox

    <ListBox>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ListBox}}" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>

    原始尺寸图片

    <Style x:Key="ActualImage" TargetType="Image">
            <Setter Property="Stretch" Value="Fill"/>
            <Setter Property="Width" Value="{Binding Source.PixelWidth, RelativeSource={RelativeSource Self}}"/>
            <Setter Property="Height" Value="{Binding Source.PixelHeight, RelativeSource={RelativeSource Self}}"/>
        </Style>

    图片按钮

        <Style x:Key="ImageButton" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.7" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    弹性按钮

    <Style x:Key="GrowButton" TargetType="Button">
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Duration="0:0:.25" From="1" To=".7" AutoReverse="True"/>
                                            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Duration="0:0:.25" From="1" To=".7" AutoReverse="True"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.7" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    无样式控件

    <Style x:Key="PlainTextBox" TargetType="{x:Type TextBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <ScrollViewer x:Name="PART_ContentHost" VerticalContentAlignment="Center" Background="{TemplateBinding Background}" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="PlainPasswordBox" TargetType="{x:Type PasswordBox}">
            <Setter Property="PasswordChar" Value="●"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type PasswordBox}">
                        <ScrollViewer x:Name="PART_ContentHost" VerticalContentAlignment="Center" Background="{TemplateBinding Background}" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="PlainRadio" TargetType="RadioButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <ContentPresenter Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
  • 相关阅读:
    KALI LINUX 核心概念讲解,持续更新
    KALI LINUX 工具大全之密码破解 --- BruteSpray ( 暴力喷雾 )
    android studio的 gradle 依赖同步错误解决方法
    安卓逆向的初步研究--从某恋app入手
    nc浏览器的十宗罪
    手机重要文件目录(换新机可能要用到)
    国产手机的谷X服务
    安卓手机设置的那些琐事
    办公中遇见的那些问题
    装系统遇到的那些问题
  • 原文地址:https://www.cnblogs.com/yetsen/p/13549642.html
Copyright © 2020-2023  润新知