我从这里开始:WPF GridViewHeader样式问题
对此:

现在我只需要摆脱"Size"标题右侧的空白区域.我基本上有一个GridViewColumnHeader模板,使其成为一个TextBlock.有什么方法可以设置该标题区域的背景,以便它跨越GridView的整个宽度?
新增代码:
这是我最右边的专栏.网格不会跨越100%的可用窗口区域.在标题中,我需要此列右侧的所有内容与列标题本身具有相同的背景.
<Style x:Key="GridHeaderRight" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<TextBlock Text="{TemplateBinding Content}" Padding="5" Width="{TemplateBinding Width}" TextAlignment="Right">
<TextBlock.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#373638" />
<GradientStop Offset="1.0" Color="#77797B" />
</LinearGradientBrush>
</TextBlock.Background>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#373638" />
<GradientStop Offset="1.0" Color="#77797B" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<GridViewColumn Width="200" HeaderContainerStyle="{ StaticResource …Run Code Online (Sandbox Code Playgroud) 你如何在WPF中相当于css的margin-top?
我有一个图像,我想在顶部添加一个边距,但我似乎可以开始工作的是边距,这会影响图像的每一面.
我刚开始使用MV-VM和WPF,并且遇到了解一些绑定问题的问题.
我有一个登录页面,其中包含a ComboBox和a PasswordBox.该ComboBox如下所示:
<ComboBox Name="comboBox1" SelectedItem="{Binding Path=Username}">
Run Code Online (Sandbox Code Playgroud)
这工作得很好 - 每次SelectedItem更改时我的值都会更新ComboBox!
在我的ViewModel中,我有一个ICommand使用此方法来确定Login按钮是否处于活动状态:
public bool CanLogin()
{
return !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我没有PasswordBox绑定ViewModel上的Password属性 - 所以我没有办法告诉它什么时候更新.
那么如何获取PasswordBoxViewModel 的值呢?我读过的所有内容都说不出PasswordBox于安全原因而绑定.我只是取消了CanLogin()的密码限制,但我需要将值传递给AccountService.
我正在尝试设置我的第一个WPF ListView/GridView,并且无法设置列标题的样式.我目前有3个问题.以下是GridView的视图:
替代文字http://img195.imageshack.us/img195/3245/wpfgridview.png
我想删除分隔列标题的小白色垂直边框.
我想删除MouseOver效果.此屏幕截图将鼠标悬停在第3列上,将背景变为白色.
如何在不将其拧紧的情况下覆盖单个列上的水平对齐?
这就是代码的样子:
<Style x:Key="GrayHeader" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#373638" />
<GradientStop Offset="1.0" Color="#57595B" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="White" />
<Setter Property="Padding" Value="5, 5" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
<ListView ItemsSource="{Binding Source={StaticResource
EmployeeInfoDataSource}}"
Margin="0,20,0,20">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" >
<Setter Property="Height" Value="24" />
<Setter Property="Background" Value="#7BB3DC" />
<Setter Property="Foreground" Value="#000000" />
<Setter Property="FontSize" Value="12" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="BorderThickness" Value="1" /> …Run Code Online (Sandbox Code Playgroud) 我有一个GridView,其中包含文件列表,创建日期和文件大小.在网格下方,我有一个文本块,上面写着"X Files Selected.Y MB".我可以很好地绑定到SelectedItems.Count,但是我可以轻松地绑定到所选文件大小的总和吗?
下面的问号应该是SelectedItems fileSize列值的总和.有任何想法吗?
<TextBlock HorizontalAlignment="Right">
<TextBlock.Text>
<MultiBinding StringFormat=" {0} Files Selected. {1} MB">
<Binding ElementName="FilesList" Path="SelectedItems.Count"></Binding>
<Binding ElementName="FilesList" Path="SelectedItems.?????"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
我知道我可以在代码隐藏中完成这项工作 - 但是我希望将我的代码隐藏为空并在XAML中执行.这是代码隐藏代码:
private void FilesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
double x = 0;
foreach (FileInfo fileInfo in FilesList.SelectedItems)
{
x += fileInfo.Length;
}
}
Run Code Online (Sandbox Code Playgroud)