我的问题可能听起来有点愚蠢,但每当我面对它时它都会让我感到烦恼.有什么区别:
where value.HasValue
Run Code Online (Sandbox Code Playgroud)
和
where value != null
Run Code Online (Sandbox Code Playgroud)
HasValue检查是否value
为null?
Ok i have a WPF application in which i have a resource dictionary. In the dictionary i have a new style for a Button
that looks like this :
<Style x:Key="MenuButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image x:Name="Imager" RenderOptions.BitmapScalingMode="HighQuality" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="UniformToFill"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Imager" Property="Width" Value="24" />
<Setter TargetName="Imager" Property="Height" Value="24" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Imager" Property="Width" Value="16" />
<Setter TargetName="Imager" Property="Height" …
Run Code Online (Sandbox Code Playgroud) 好吧,我有一个WPF应用程序,我ListBoxItem
在资源字典中创建自己的,如下所示:
<DataTemplate x:Key="StationItem">
<Grid x:Name="Gridder" Tag="{Binding SItem.StationName}" Width="125" Height="55">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Rectangle x:Name="Rectagler" Width="120" Height="50" RadiusX="5" RadiusY="5" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.ColumnSpan="2" Grid.RowSpan="2" StrokeThickness="1" Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFF3A00" Offset="0"/>
<GradientStop Color="#FFE88D20" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" x:Name="StationName" Text="{Binding SItem.StationName}" Foreground="Black" FontSize="14" FontWeight="SemiBold" TextWrapping="NoWrap" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0"/>
<TextBlock Grid.Column="0" Grid.Row="1" x:Name="StationCountry" Text="{Binding SItem.StationCountry}" Foreground="WhiteSmoke" FontSize="11" FontWeight="Light" TextWrapping="NoWrap" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,8"/>
<Image Tag="{Binding SItem.StationName}" Width="15" Height="15" …
Run Code Online (Sandbox Code Playgroud) 好的,我的项目资源大约有5个Images
.我想做的是Image.Source
从我的项目资源中绑定一个.Im C#编码非常简单,我只是这样做:
ImageHolder.Source = Propetries.Resources.Image1.png
.
如何在XAML中完成?像这样的东西:
<Image Source={??????}/>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
好吧,我有一个WPF项目,其中我有4个TexBlock
.我想要的是改变Text
每个TextBlock
通道Binding
.
到目前为止,我有我的XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="First" Text="{Binding FirstString}" Grid.Row="0"/>
<TextBlock x:Name="Second" Text="{Binding SecondString}" Grid.Row="1"/>
<TextBlock x:Name="Third" Text="{Binding ThirdString}" Grid.Row="2"/>
<TextBlock x:Name="Fourth" Text="{Binding FourthString}" Grid.Row="3"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
在我的代码中我有:
public partial class MainWindow : Window
{
public string FirstString { get; set; }
public string SecondString { get; set; }
public string ThirdString { get; set; }
public string FourthString { get; set; }
public MainWindow() …
Run Code Online (Sandbox Code Playgroud) 我有一个类,它描述了一个人的名字和姓氏,如下所示:
public class Person
{
string firstname;
string lastname;
}
Run Code Online (Sandbox Code Playgroud)
还有一个列表,我在其中添加如下Person
项目:
List<Person> PersonList;
Run Code Online (Sandbox Code Playgroud)
我使用Xml序列化后填写列表.当我检查列表容量时,一切似乎都没问题.
我的问题是,如何从列表中访问人名或姓?