C# 如何从一些选项卡中选择网格列并在另一个选项卡中显示它们?
我正在创建一个带有TabControl的WPF应用程序(UI),其中包含四个TabItems。 --C# 如何从一些选项卡中选择网格列并在另一个选项卡中显示它们?,c#,wpf,tabs,grid,C#,Wpf,Tabs,Grid,我正在创建一个带有TabControl的WPF应用程序(UI),其中包含四个TabItems。 -- 从中,我想以某种方式(可能通过复选框或任何其他方式)选择哪个GridColumns将显示在用户选项卡上。我可以使用其他选项卡,但有时我需要让用户有机会只使用他/她想要的特定输出。我怎样才能做到这一点?我是C#和wpf的新手,所以如果您能解释一个简单的解决方案并提供一些代码,我将不胜感激 在回答您的问题之前,给您一个简短的提示:当您提问时,请发布一些代码,否则很难有人花时间帮助您 要实现应用程序,
从中,我想以某种方式(可能通过复选框或任何其他方式)选择哪个GridColumns将显示在用户选项卡上。我可以使用其他选项卡,但有时我需要让用户有机会只使用他/她想要的特定输出。我怎样才能做到这一点?我是C#和wpf的新手,所以如果您能解释一个简单的解决方案并提供一些代码,我将不胜感激 在回答您的问题之前,给您一个简短的提示:当您提问时,请发布一些代码,否则很难有人花时间帮助您 要实现应用程序,您需要考虑:
ColumnDefinitions
属性中工作public class ElementSpy : Freezable
{
private DependencyObject element;
public static ElementSpy GetNameScopeSource(DependencyObject obj)
{
return (ElementSpy)obj.GetValue(NameScopeSourceProperty);
}
public static void SetNameScopeSource(DependencyObject obj, ElementSpy value)
{
obj.SetValue(NameScopeSourceProperty, value);
}
public static readonly DependencyProperty NameScopeSourceProperty =
DependencyProperty.RegisterAttached("NameScopeSource", typeof(ElementSpy), typeof(ElementSpy),
new UIPropertyMetadata(null, OnNameScopeSourceProperty));
private static void OnNameScopeSourceProperty(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
INameScope nameScope;
ElementSpy elementSpy = args.NewValue as ElementSpy;
if (elementSpy != null && elementSpy.Element != null)
{
nameScope = NameScope.GetNameScope(elementSpy.Element);
if (nameScope != null)
{
d.Dispatcher.BeginInvoke(new Action<DependencyObject, INameScope>(SetScope),
System.Windows.Threading.DispatcherPriority.Normal,
d, nameScope);
}
}
}
private static void SetScope(DependencyObject d, INameScope nameScope)
{
NameScope.SetNameScope(d, nameScope);
}
public DependencyObject Element
{
get
{
if (element == null)
{
PropertyInfo propertyInfo = typeof(Freezable).GetProperty("InheritanceContext",
BindingFlags.NonPublic | BindingFlags.Instance);
element = propertyInfo.GetValue(this, null) as DependencyObject;
if (element != null)
{
Freeze();
}
}
return element;
}
}
protected override Freezable CreateInstanceCore()
{
return new ElementSpy();
}
}
当然,这只是一个示例原型,但我相信它可以帮助您使用应用程序。在回答您的问题之前,给您一个简短提示:当您提问时,请发布一些代码,否则很难有人花时间帮助您 要实现应用程序,您需要考虑:
ColumnDefinitions
属性中工作public class ElementSpy : Freezable
{
private DependencyObject element;
public static ElementSpy GetNameScopeSource(DependencyObject obj)
{
return (ElementSpy)obj.GetValue(NameScopeSourceProperty);
}
public static void SetNameScopeSource(DependencyObject obj, ElementSpy value)
{
obj.SetValue(NameScopeSourceProperty, value);
}
public static readonly DependencyProperty NameScopeSourceProperty =
DependencyProperty.RegisterAttached("NameScopeSource", typeof(ElementSpy), typeof(ElementSpy),
new UIPropertyMetadata(null, OnNameScopeSourceProperty));
private static void OnNameScopeSourceProperty(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
INameScope nameScope;
ElementSpy elementSpy = args.NewValue as ElementSpy;
if (elementSpy != null && elementSpy.Element != null)
{
nameScope = NameScope.GetNameScope(elementSpy.Element);
if (nameScope != null)
{
d.Dispatcher.BeginInvoke(new Action<DependencyObject, INameScope>(SetScope),
System.Windows.Threading.DispatcherPriority.Normal,
d, nameScope);
}
}
}
private static void SetScope(DependencyObject d, INameScope nameScope)
{
NameScope.SetNameScope(d, nameScope);
}
public DependencyObject Element
{
get
{
if (element == null)
{
PropertyInfo propertyInfo = typeof(Freezable).GetProperty("InheritanceContext",
BindingFlags.NonPublic | BindingFlags.Instance);
element = propertyInfo.GetValue(this, null) as DependencyObject;
if (element != null)
{
Freeze();
}
}
return element;
}
}
protected override Freezable CreateInstanceCore()
{
return new ElementSpy();
}
}
当然,这只是一个示例原型,但我相信它可以帮助您开发应用程序
public class BooleanWidthConverter : IValueConverter
{
private static GridLength star = new GridLength(1, GridUnitType.Star);
private static GridLength zero = new GridLength(0, GridUnitType.Pixel);
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool boolValue = (bool)value;
return boolValue ? star : zero;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}