我在我的窗口资源中定义了一个自定义集合,如下所示(在Sketchflow应用程序中,因此窗口实际上是一个UserControl):
<UserControl.Resources>
<ds:MyCollection x:Key="myKey" x:Name="myName" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
我希望能够在代码隐藏中引用这个集合,我期望它是由x:Name,但我似乎无法访问它.
我可以使用它来获取它的引用
myRef = (MyCollection) this.FindName("myKey");
Run Code Online (Sandbox Code Playgroud)
但这似乎是hackish.这是不好的做法,还有什么会更好?谢谢 :)
我刚学习WPF中的样式和控件模板如何影响按钮的外观,
我正在尝试设置Button的FlatStyle,在我见过的资源中找不到任何告诉我如何做到这一点的东西,在Windows Forms中,这是通过FlatStyle = Flat设置的.
如何在WPF中做到这一点?
当我从本文运行以下Northwind WPF Toolkit Datagrid代码时,我得到了一个数据网格,但是没有滚动条,因此用户只能看到部分数据网格.我使用的是2009年3月的最新版本.
我需要指定什么才能使WPF Datagrid具有滚动条?
我尝试将数据网格放在ScrollViewer中,但这没有帮助.
XAML:
<Window x:Class="TestDataGrid566.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Window1" Height="600" Width="800">
<StackPanel>
<toolkit:DataGrid x:Name="TheDataGrid" AutoGenerateColumns="True"/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
后台代码:
using System.Linq;
using System.Windows;
using TestDataGrid566.Model;
namespace TestDataGrid566
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
NorthwindDataContext db = new NorthwindDataContext();
var customers = from c in db.Customers
select c;
TheDataGrid.ItemsSource = customers;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个订单输入表单,其中包含一个ListBox包含订单项列表的表单.我有我的项目模板,其中一个值是ComboBox我的每个项目中的一个.
现在,我的状态还可以创建贷项通知单的,除了采购订单,但是当我创建一个贷项通知单,我希望把话说"贷项通知单"在列表框中,然而,TextBlock盖了ComboBox两个我行项目.我想将点击事件传递TextBlock给ComboBoxes,但我不知道该怎么做.
这就是我所拥有的,(也许我对此完全错了,我有点像WPF的菜鸟)
<ListBox SelectionMode="Single" Grid.Row="2"
ItemsSource="{Binding Path=LineItems}" HorizontalContentAlignment="Stretch"
IsSynchronizedWithCurrentItem="True" Background="#66FFFFFF">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="BorderThickness" Value="1" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsPartBackOrder}" Value="True">
<Setter Property="Background" Value="Orange" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type Entities:SalesOrderLineItem}" >
<OrderEntry:SalesOrderLineItemCreate DataContext="{Binding}" DeleteSalesOrderLineItem="DeleteSalesOrderLineItem" Margin="0,3,3,0" >
<OrderEntry:SalesOrderLineItemCreate.Resources>
<Style TargetType="{x:Type OrderEntry:SalesOrderLineItemCreate}">
<Style.Triggers>
<DataTrigger
Binding="{Binding RelativeSource=
{
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListBoxItem}
},
Path=IsSelected
}" Value="True">
<Setter Property="Background" Value="LightBlue" />
<Setter Property="Foreground" …Run Code Online (Sandbox Code Playgroud) 我有以下xaml:
<DockPanel>
<DockPanel.Resources>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Yellow"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="Green"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Resources>
<Button Content="Cut" Height="30" Width="75"/>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在按钮上时,前景变为黄色,然后当我按下按钮时,前景变为绿色.
现在,如果我在XAML中反转触发器的顺序,当我将鼠标悬停在它上面时,前景会变为黄色,但是当我按下按钮时,前景不会变为绿色.
对此有何解释?一个触发器是否会覆盖另一个触发器?
如何使用WinForms中的ActiveForm属性来引用C#中的活动Window of WPF应用程序?
我想在代码中生成相当于XAML中的这个:
<TextBlock
Text="Title:"
Width="{Binding FormLabelColumnWidth}"
Style="{DynamicResource FormLabelStyle}"/>
Run Code Online (Sandbox Code Playgroud)
我可以做文本和宽度,但是如何将动态资源分配给样式:
TextBlock tb = new TextBlock();
tb.Text = "Title:";
tb.Width = FormLabelColumnWidth;
tb.Style = ???
Run Code Online (Sandbox Code Playgroud) 可以设置一个Icon,以便在当前应用程序的每个窗口中使用它.所以我设置了一次(不是手动每个窗口)..?