Tag: datatemplate

WPF列表框为空的数据模板

我想知道人们如何处理没有项目的ListBox控件? 例如,我想绑定一个search结果列表,但如果没有find结果,我想显示“找不到结果”。 我目前解决这个问题的方法是,如果结果集计数= 0,则隐藏列表框,并显示带有“未find结果”消息的标签。 理想情况下,我想像ASP .NET datagrid EmptyTemplate解决scheme。 干杯

连接string,而不是使用一堆TextBlocks

我想在WPF ItemsControl中显示Customer对象的列表。 我为此创build了一个DataTemplate: <DataTemplate DataType="{x:Type myNameSpace:Customer}"> <StackPanel Orientation="Horizontal" Margin="10"> <CheckBox"></CheckBox> <TextBlock Text="{Binding Path=Number}"></TextBlock> <TextBlock Text=" – "></TextBlock> <TextBlock Text="{Binding Path=Name}"></TextBlock> </StackPanel> </DataTemplate> 所以我想要的基本上是一个简单的列表(checkbox),其中包含NUMBER – 名称。 是不是有一种方法可以在绑定部分中直接连接数字和名称?

在代码隐藏的DataTemplate中find一个WPF元素

我有一个数据模板 <Window.Resources> <DataTemplate x:Key="BarChartItemsTemplate"> <Border Width="385" Height="50"> <Grid> <Rectangle Name="rectangleBarChart" Fill="MediumOrchid" StrokeThickness="2" Height="40" Width="{Binding}" HorizontalAlignment="Right" VerticalAlignment="Bottom"> <Rectangle.LayoutTransform> <ScaleTransform ScaleX="4"/> </Rectangle.LayoutTransform> </Rectangle> <TextBlock Margin="14" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding}"> <TextBlock.LayoutTransform> <TransformGroup> <RotateTransform Angle="90"/> <ScaleTransform ScaleX="-1" ScaleY="1"/> </TransformGroup> </TextBlock.LayoutTransform> </TextBlock> </Grid> </Border> </DataTemplate> </Window.Resources> 我在表格上有一个button。 我需要从dataTemplate改变比例(scaleTransform)矩形。 我该如何访问上述button的Button_Click事件中的“rectangleBarChart”元素?

如何在C#代码中构buildDataTemplate?

我正在尝试构build一个winform互操作的下拉列表,并在代码中创build下拉列表。 但是,我得到的数据绑定基于我指定的DataTemplate的问题。 我错过了什么? drpCreditCardNumberWpf = new ComboBox(); DataTemplate cardLayout = new DataTemplate {DataType = typeof (CreditCardPayment)}; StackPanel sp = new StackPanel { Orientation = System.Windows.Controls.Orientation.Vertical }; TextBlock cardHolder = new TextBlock {ToolTip = "Card Holder Name"}; cardHolder.SetBinding(TextBlock.TextProperty, "BillToName"); sp.Children.Add(cardHolder); TextBlock cardNumber = new TextBlock {ToolTip = "Credit Card Number"}; cardNumber.SetBinding(TextBlock.TextProperty, "SafeNumber"); sp.Children.Add(cardNumber); TextBlock notes = […]