0
点赞
收藏
分享

微信扫一扫

WPF给登录password加密,跳出当前绑定找其他方法

前端王祖蓝 2022-01-30 阅读 55

如果使用TextBox做密码框,有一种简单方法加密

                   <TextBox.Style>
                        <Style TargetType="{x:Type TextBox}">
                            <Setter Property="TextDecorations">
                                <Setter.Value>
                                    <TextDecorationCollection>
                                        <TextDecoration>
                                            <TextDecoration.Pen>
                                                <Pen
                                                    Brush="Black"
                                                    DashCap="Round"
                                                    EndLineCap="Round"
                                                    StartLineCap="Round"
                                                    Thickness="10">
                                                    <Pen.DashStyle>
                                                        <DashStyle Dashes="0.0,1.2" Offset="0.6" />
                                                    </Pen.DashStyle>
                                                </Pen>
                                            </TextDecoration.Pen>
                                            <TextDecoration.Location>
                                                <TextDecorationLocation>Strikethrough</TextDecorationLocation>
                                            </TextDecoration.Location>
                                        </TextDecoration>
                                    </TextDecorationCollection>
                                </Setter.Value>

                            </Setter>
                            <Setter Property="Height" Value="30" />
                            <Setter Property="Background" Value="#FF484D5E" />
                            <Setter Property="Foreground" Value="Transparent" />
                            <Setter Property="FontSize" Value="20" />
                            <Setter Property="FontFamily" Value="Courier New" />
                        </Style>
                    </TextBox.Style>

附加一种表格跳出当前绑定找祖先的方法

        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="60"/>
            </Grid.RowDefinitions>
            <DataGrid ItemsSource="{Binding CargoTypes}" AutoGenerateColumns="False" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="编号" Binding="{Binding Id}" />
                    <DataGridTextColumn Header="物资名称" Binding="{Binding Name}"/>
                    <DataGridTextColumn Header="备注" Binding="{Binding Tag}"/>
                    <DataGridTextColumn Header="插入日期" Binding="{Binding InsertDate}"/>
                    <DataGridTextColumn Header="登录员" Binding="{Binding MemberName}"/>
                    <DataGridTemplateColumn Header="操作">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="删除" HorizontalAlignment="Center">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Foreground" Value="Red"/>
                                                    <Setter Property="Cursor" Value="Hand"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                    <b:Interaction.Triggers>
                                        <b:EventTrigger EventName="MouseUp">
                                            <b:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:CargoTypeView},Path=DataContext.DeleteCargoTypeCommand}"
                                                                   CommandParameter="{Binding}"/>
                                        </b:EventTrigger>
                                    </b:Interaction.Triggers>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>                
            </DataGrid>
            <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
                <TextBlock Text="统计:" FontSize="16" Foreground="White"/>
                <TextBlock Text="{Binding CargoTypes.Count}" FontSize="16" Foreground="White"/>
            </StackPanel>
        </Grid>

如果 CommandParameter="{Binding}",则CommandParameter将会把CargoTypes List中 的一个随机实体(类型为CargoType)传到 RelayCommand DeleteCargoCommand 中去。只需要判断传入的参数是否为CargoType,可以做下一步的逻辑

        public RelayCommand<object> DeleteCargoCommand
        {
            get
            {
                return new RelayCommand<object>((arg) =>
                {
                   

                    if (!(arg is Cargo model)) return;
                    var count = new CargoProvider().Delete(model);
                    if (count > 0) MessageBox.Show("操作成功");
                    Cargos = new CargoProvider().Select();//刷新数据
                });
            }
        }
        private List<CargoType> cargoTypes = new List<CargoType>();
        /// <summary>
        /// 所有物资类型
        /// </summary>
        public List<CargoType> CargoTypes
        {
            get
            {
                return cargoTypes;
            }
            set
            {
                cargoTypes = value;
                RaisePropertyChanged();
            }
        }       

举报

相关推荐

0 条评论