我有以下示例代码,每次按下按钮时缩放:
XAML:
<Window x:Class="WpfApplication12.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Canvas x:Name="myCanvas">
<Canvas.LayoutTransform>
<ScaleTransform x:Name="myScaleTransform" />
</Canvas.LayoutTransform>
<Button Content="Button"
Name="myButton"
Canvas.Left="50"
Canvas.Top="50"
Click="myButton_Click" />
</Canvas>
</Window>
Run Code Online (Sandbox Code Playgroud)
*的.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("scale {0}, location: {1}",
myScaleTransform.ScaleX,
myCanvas.PointToScreen(GetMyByttonLocation()));
myScaleTransform.ScaleX =
myScaleTransform.ScaleY =
myScaleTransform.ScaleX + 1;
Console.WriteLine("scale {0}, location: {1}",
myScaleTransform.ScaleX,
myCanvas.PointToScreen(GetMyByttonLocation()));
}
private Point GetMyByttonLocation()
{
return new Point(
Canvas.GetLeft(myButton),
Canvas.GetTop(myButton));
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
scale 1, location: …Run Code Online (Sandbox Code Playgroud) 我有一些奇怪的行为,我似乎无法解决.当我遍历ListBox.ItemsSource属性中的项目时,我似乎无法获取容器?我期待看到一个ListBoxItem返回,但我只得到null.
有任何想法吗?
这是我正在使用的一些代码:
this.lstResults.ItemsSource.ForEach(t =>
{
ListBoxItem lbi = this.lstResults.ItemContainerGenerator.ContainerFromItem(t) as ListBoxItem;
if (lbi != null)
{
this.AddToolTip(lbi);
}
});
Run Code Online (Sandbox Code Playgroud)
ItemsSource当前设置为Dictionary并且包含许多KVP.
我有下一个代码,我定义了一个名为dgQuery的WPF工具包数据网格控件; 我用数据集的信息填充了这个,然后我在dgQuery中插入了一个新的复选框列来检查/取消选中某些行,我展示了部分C#代码:
dgQuery.DataContext = dS.Tables[0];
DataGridTemplateColumn cbCol = new DataGridTemplateColumn();
cbCol.Header = "Opc";
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CheckBox));
Binding bind = new Binding("IsSelected");
bind.Mode = BindingMode.TwoWay;
factory.SetValue(CheckBox.IsCheckedProperty, bind);
DataTemplate cellTemplate = new DataTemplate();
cellTemplate.VisualTree = factory;
cbCol.CellTemplate = cellTemplate;
dgQuery.Columns.Insert(0, cbCol);
Run Code Online (Sandbox Code Playgroud)
在检查/取消选中dgQuery行的新复选框列后,我将单击一个按钮,仅将我检查的行保存到数据库中.问题是,如何开发用于读取dgQuery的所有行的循环以及让我知道哪些行具有选中/取消选中复选框的条件?请帮我举个例子.
谢谢!!
wpf ×3
c# ×2
.net ×1
containers ×1
datagrid ×1
itemssource ×1
listbox ×1
wpfdatagrid ×1
wpftoolkit ×1
xaml ×1