[英]C# WPF - Switching between Grids
i am almost new to C# with WPF. 我几乎是WPF的C#新手。 I have a small problem.
我有一个小问题。 Maybe the solution is very easy, but i don't see it right now.
也许解决方案很简单,但是我现在看不到它。 So i want to make different TABLES.
所以我想做不同的表。 I use Grids to make my own table.
我使用网格制作自己的表。 Now i want to switch between the tables at different states of my application, so that i make a grid invisible and the one i need visible.
现在,我想在应用程序处于不同状态的表之间切换,以便使网格不可见,而使我需要的网格可见。 How do i implement several grid tables in XAML?
如何在XAML中实现几个网格表? For example i have a tabcontrol and in the tabitem i want to place more than one grids, but thats not possible.
例如,我有一个tabcontrol,在tabitem中,我想放置多个网格,但是那是不可能的。 I tried using StackPanel for example but then i have a gap at the bottom of the grid.
例如,我尝试使用StackPanel,但是在网格底部有一个缺口。 I need a way to define several grids and switch between them.
我需要一种定义几个网格并在它们之间切换的方法。 Before C# i worked with MATLAB and i just put every table in a PANEL and switched them visible and invisible when i needed them.
在使用C#之前,我使用过MATLAB,只是将每个表放在PANEL中,并在需要时将它们切换为可见和不可见。 Is there no similar way in WPF?
WPF中没有类似的方法吗?
Greetings 问候
In such cases, i would go with UserControls. 在这种情况下,我将使用UserControls。 One usercontrol for each grid type.
每种网格类型都有一个用户控件。 A sample (not related to Grid in question) would be like the below.
一个示例(与所讨论的网格无关)如下所示。
<Window.Resources> <ResourceDictionary> <DataTemplate x:Key="DTGlobalAdminManager"> <AC:UCGlobalAdmin DataContext="{Binding Source={x:Static GVM:VMAdminConsole.Instance}, Path=ViewModelGlobalAdmin}"/> </DataTemplate> <DataTemplate x:Key="DTCompanyAdminProjects"> <AC:UCCompanyAdmin DataContext="{Binding Source={x:Static GVM:VMAdminConsole.Instance}, Path=ViewModelCompanyAdmin}" /> </DataTemplate> <DataTemplate x:Key="DTProjectAdminManager"> <AC:UCProjectAdminManage DataContext="{Binding Source={x:Static GVM:VMAdminConsole.Instance}, Path=ViewModelProjectAdmin}"/> </DataTemplate> <DataTemplate x:Key="DTGlobalAdminAssignCategories"> <AC:UCGlobalAdminCategories DataContext="{Binding Source={x:Static GVM:VMAdminConsole.Instance}, Path=ViewModelGlobalAdmin}"/> </DataTemplate> </ResourceDictionary> </Window.Resources>
You can set up a content control and different usercontrols (each containing different grid template). 您可以设置内容控件和不同的用户控件(每个用户控件包含不同的网格模板)。 Then switch them using a Style Trigger.
然后使用样式触发器进行切换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.