• 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>
  • 相关阅读:
    大整数相加算法
    java中String和char的区别
    Git命令
    Dart随记
    用nodejs或者Chrome控制台的js对URI进行编码或解码
    Rust执行cmd或shell命令
    cargo expand用于查看被宏隐藏的代码
    Blocking waiting for file lock on package cache
    Rust生命周期之个人理解
    Rust为基础类型实现Trait
  • 原文地址:https://www.cnblogs.com/yetsen/p/13549642.html
Copyright © 2020-2023  润新知