小编Il *_*Vic的帖子

如何从文件名中获取图像尺寸

我有一个名为FPN ="c:\ ggs\ggs Access\images\members\1.jpg"的文件

我正在尝试获取图像1.jpg的尺寸,并且我想在加载之前检查图像尺寸是否有效,并且如果图像的宽度或高度小于或等于零,则弹出像"图像格式不正确"这样的消息

有人可以帮我吗?

c# image dimensions

54
推荐指数
2
解决办法
8万
查看次数

如何二进制序列化器自定义类

我有这个自定义类:

public class MyClass
{ 
    private byte byteValue;
    private int intValue;
    private MyClass myClass1= null;
    private MyClass myClass2 = null;
}
Run Code Online (Sandbox Code Playgroud)

显然我也有构造函数和 get/set 方法。

在我的主窗体中,我初始化了很多MyClass对象(请注意,在MyClass对象中我引用了其他 2 个 MyClass 对象)。初始化后,我遍历第一MyClass项,例如将其称为“root”。所以,例如我做这样的事情:

MyClass myClassTest = root.getMyClass1();
MyClass myClassTest2 = myClassTest.getMyClass1();
Run Code Online (Sandbox Code Playgroud)

等等。

不,我想将所有MyClass对象存储在一个二进制文件中,以便在软件重新启动后再次获取它们。

我完全不知道如何做到这一点,有人可以帮助我吗?谢谢。

c# binary serialization binaryfiles deserialization

3
推荐指数
1
解决办法
9593
查看次数

WPF-如何在数据网格中获取选定的行索引?

我在数据网格中有文本框。数据取自数据库。假设我有 10 行这些文本框值。一旦我点击这一行,就能够获得这个选定的行索引。我的目标是,如果一旦文本框值发生变化,我需要检测它是哪一行(哪个值)并根据该值进行一些计算,然后需要显示同一行的另一个字段。所以我可以知道哪一行被击中。`我正在使用带有以下声明的 Datagrid:

    <dg:DataGrid Name="dgBudgetAllocation" CanUserDeleteRows="False" CanUserAddRows="False" CanUserSortColumns="True"
                        IsSynchronizedWithCurrentItem="True" MaxHeight="400" RowHeight="70" SelectionUnit="Cell" SelectedValue="" SelectionMode="Single"
                 AutoGenerateColumns="False" GridLinesVisibility="None"  HeadersVisibility="Column"  PreviewMouseDown="DgBudgetAllocation_OnPreviewMouseDown" SelectedCellsChanged="DgBudgetAllocation_OnSelectedCellsChanged" MouseDown="DgBudgetAllocation_OnMouseDown" PreviewMouseUp="DgBudgetAllocation_OnPreviewMouseUp"  PreviewKeyDown="DgBudgetAllocation_OnPreviewKeyDown" HorizontalAlignment="Left">


                       <dg:DataGridTemplateColumn Header="Budget Type" SortMemberPath="BUDGETYPE"
                                       MinWidth="50" HeaderStyle="{DynamicResource dgHeaderLeftJust}" CellStyle="{DynamicResource dgColumnRightJust}">
                <dg:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding BUDGETYPE}" HorizontalAlignment="left" VerticalAlignment="Top" Margin="0,0,3,0" />
                    </DataTemplate>
                </dg:DataGridTemplateColumn.CellTemplate>

            </dg:DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)

我根据不同的人的建议尝试了以下代码段。对于所有我得到的选定索引是-1。

DataRowView drv = (DataRowView)dgBudgetAllocation.SelectedItem;
                object item = dgBudgetAllocation.SelectedItem;
                string ID = (dgBudgetAllocation.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
                DataGrid row1 = (DataGrid)dgBudgetAllocation.SelectedItems[1];
                var row = dgBudgetAllocation.SelectedItems[0]; 
Run Code Online (Sandbox Code Playgroud)

没有任何工作。请建议我如何进一步进行。

c# wpf datagrid wpfdatagrid

3
推荐指数
1
解决办法
1万
查看次数

按回车键时在文本框上执行命令

我是 WPF 的新手,我看到了最好的模式调用 MVVM。我尝试深入研究,发现该命令只能在按钮或菜单项等上执行。完成我的编辑。我有谷歌这个,但我没有从所有答案中得到任何答案。所以希望大家帮帮我。在文本框中按回车键时如何执行命令?

c# wpf xaml mvvm

1
推荐指数
1
解决办法
2484
查看次数

WPF PasswordBox 圆角

我用它来圆化 TextBox 的角,

    <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
        <Border Background="{TemplateBinding Background}" 
            x:Name="Bd" BorderBrush="#FFE6DDDD"
            BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
            <ScrollViewer x:Name="PART_ContentHost"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
            <Trigger Property="Width" Value="Auto">
                <Setter Property="MinWidth" Value="100"/>
            </Trigger>
            <Trigger Property="Height" Value="Auto">
                <Setter Property="MinHeight" Value="20"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我申请,

        <TextBox Template="{StaticResource TextBoxBaseControlTemplate}"
             Height="25"
             Margin="168,100,139,194"
             HorizontalContentAlignment="Center"
             VerticalContentAlignment="Center"
             Background="{x:Null}"
             BorderBrush="{x:Null}"
             FontFamily="Aller Light">              
        </TextBox>
Run Code Online (Sandbox Code Playgroud)

任务完成

在此处输入图片说明

然后我想在PasswordBox中做,

    <ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}">
        <Border Background="{TemplateBinding Background}" 
            x:Name="Bd" BorderBrush="#FFE6DDDD"
            BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
        </Border>
        <ControlTemplate.Triggers>
            <Trigger …
Run Code Online (Sandbox Code Playgroud)

wpf xaml

0
推荐指数
1
解决办法
3645
查看次数