发布网友 发布时间:2022-04-21 19:37
共2个回答
热心网友 时间:2023-11-10 21:58
你应该用百分比,而不应该用*或固定值
上面的代码的意思是第一列的长度为300的20%即60,第二列的长度为300的50%,
当然,你可以把width="300"去掉,这样列的长度就由上一级容器的长度决定,要是上一级还没有长度就继续寻找上一级,直到到达根元素
热心网友 时间:2023-11-10 21:58
步骤。
private void ListBoxItem_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.Key == Key.F2)
{
ListBoxItem myListBoxItem = (ListBoxItem)(listbox.ItemContainerGenerator.ContainerFromItem(listbox.Items.CurrentItem));
ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(myListBoxItem);
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
TextBox myTextBox = (TextBox)myDataTemplate.FindName("textbox", myContentPresenter);
MessageBox.Show("The text of the TextBlock of the selected list item:" + myTextBox.Text);
}
}
private childItem FindVisualChild<childItem>(DependencyObject obj)
where childItem : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else
{
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}