我认为在这种情况下,一张图片胜过千言万语:
XAML:
<Grid>
<ItemsControl ItemsSource="{Binding Persons}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Background="LightBlue"/>
<TextBlock Text="{Binding Age}" Background="LightPink" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
ps - 我不想为第一列设置一个特定的,但要给它所需的最大值.
更新: 我已经尝试过ColinE的链接并完成了这个:
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
Run Code Online (Sandbox Code Playgroud)
但它对我没有用.
我正在使用WPF工具包AutoCompleteBox,其itemsSource是一个数百万个对象的列表.
AutoCompleteBox是否用于搜索后台线程,如果不是,我该如何进行.
我有一个WCF项目,当我运行它时,它有时会在WCF测试中吃午餐,有时却没有.
如何设置WCF测试客户端始终显示?
如何在x#代码中将xml扁平化为一行?
之前:
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
</CATALOG>
Run Code Online (Sandbox Code Playgroud)
后:
<CATALOG><CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST>COUNTRY>USA</COUNTRY>....
Run Code Online (Sandbox Code Playgroud) 我有一个名为UserControl1的简单UserControl,它包含一个TextBlock:
<UserControl x:Class="WpfApplication2.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Text="{Binding}"/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我初始化了它的一个新实例,并在代码中给它一个DataContext.当窗口关闭时,我必须将此控件绘制到图像文件中.UserControl不会在已创建的文件中呈现有界文本.
这是我使用usercontrol的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Closing += MainWindow_Closing;
}
void MainWindow_Closing(object sender, CancelEventArgs e)
{
UserControl1 uc = new UserControl1();
uc.DataContext = "hello";
uc.Height = 100;
uc.Width = 100;
uc.Background = Brushes.LightBlue;
DrawToImage(uc);
}
private void DrawToImage(FrameworkElement element)
{
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
element.Arrange(new Rect(element.DesiredSize));
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)element.Width, (int)element.Height,
120.0, 120.0, PixelFormats.Pbgra32);
bitmap.Render(element);
BitmapEncoder encoder = …
Run Code Online (Sandbox Code Playgroud) 我正在VS2005上开发Reporting Services并且必须连接到SQL Server 2008.出现以下错误:"不支持此服务器版本.您必须具有Microsoft SQL Server 2005 Beta 2或更高版本."
我在网上找到了它的补丁,但它不起作用(链接到补丁)
"Windows Installer服务无法安装升级修补程序,因为缺少要升级的程序,或者升级修补程序可能会更新该程序的其他版本."
我还可以做些什么 ?:(
我正在使用wpf工具包AutoCompleteBox,我已经设置了Item模板.问题:弹出列表中的项目看起来很棒,但它对上面的文本框(选定项目)没有生效.
XAML:
<Controls:AutoCompleteBox x:Name="x" ItemFilter="SearchPerson" Margin="20">
<Controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<Rectangle Width="10" Height="10" Fill="LightGreen"/>
<TextBlock Text="{Binding Age}" />
</StackPanel>
</DataTemplate>
</Controls:AutoCompleteBox.ItemTemplate>
</Controls:AutoCompleteBox>
Run Code Online (Sandbox Code Playgroud)
代码背后:
public partial class MainWindow : Window
{
public List<Person> Persons { get; set; }
public MainWindow() {
InitializeComponent();
Persons = new List<Person> {
new Person{Name = "Jhon",Age=35},
new Person{Name = "Kelly",Age=40}};
x.ItemsSource = Persons;
DataContext = this;
}
bool SearchPerson(string search, object value) {
return (value as Person).Name.ToLower().Contains(search);
}
}
public class Person …
Run Code Online (Sandbox Code Playgroud) System.Windows.Data Error: 5 :
Value produced by BindingExpression is not valid for target property.;
Value='<null>' BindingExpression:Path=Attributes[AssetSL];
DataItem='DataBinding' (HashCode=4074007);
target element is 'RegionSSIn' (Name='rssi');
target property is 'AService' (type 'SLG')
Run Code Online (Sandbox Code Playgroud)
那异常是什么意思?
我正在使用NUnit并在我的一些测试中应用category属性:
[Category("FastTest")]
Run Code Online (Sandbox Code Playgroud)
这些测试必须运行得非常快,不到10秒.所以我也装饰它们
[Timeout(10000)]
Run Code Online (Sandbox Code Playgroud)
现在的问题是:
每次我使用[类别("FastTest")]在幕后装饰方法时,如何使用[Timeout(1000)]自动装饰它?
WPF - 我正在使用 BackgroundWorker 创建一个 Model3D 对象,但是当我想将它添加到 XAML 中定义的 Model3DGroup 时,出现异常:
不能使用属于与其父 Freezable 不同的线程的 DependencyObject。
这是后面的全部代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
bw.RunWorkerAsync();
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
GeometryModel3D geometryModel3D = (GeometryModel3D)e.Result;
model3DGroup.Children.Add(geometryModel3D);
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
GeometryModel3D geometryModel3D = new GeometryModel3D();
e.Result = geometryModel3D;
}
}
Run Code Online (Sandbox Code Playgroud)
这是整个 XAML:
<Grid>
<Viewport3D Margin="4,4,4,4" Grid.Row="0" Grid.Column="0">
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup …
Run Code Online (Sandbox Code Playgroud) wpf ×6
.net ×3
c# ×2
binding ×1
data-binding ×1
datacontext ×1
dispatcher ×1
grid-layout ×1
nunit ×1
render ×1
sql ×1
sql-server ×1
templates ×1
wcf ×1
wcf-client ×1
xml ×1