【问题标题】:Is there a way to display WPF Extended Toolkit's control in VS Designer?有没有办法在 VS Designer 中显示 WPF 扩展工具包的控件?
【发布时间】:2014-08-26 13:35:42
【问题描述】:

我习惯于使用设计器创建表单,并且仅在需要时手动修改 XAML。

尽管扩展工具包是一个很棒的库,但它仍然缺乏与 Visual Studio 设计器的集成。无论如何,工具包的控件是否可以像标准控件一样显示在设计器(而不是工具箱)中?如果没有,是否有解释?

目前,该工具包的控件只是空白且无法通过简单的点击来选择。

注意:问题似乎只发生在容器组件(如 BusyIndi​​cator 和 Wizard/WizardPage)上。

编辑:这是我的一些 XAML。有了这个,我可以看到向导的第一页,但看不到其他页面。如果我将我的向导放在 BusyIndi​​cator 中,则根本看不到任何东西。

<Window x:Class="MyProgram.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyProgram"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="My Program" Height="477" Width="688" MinWidth="688" MinHeight="478">
    <xctk:Wizard x:Name="wizard" FinishButtonClosesWindow="True" Next="wizard_Next">
        <xctk:WizardPage Name="Intro_Page"  Title="ABC" Description="abc" NextPage="{Binding ElementName=Second_Page}" Enter="disallowNext">
            <xctk:WizardPage.Content>
                <Grid>
                    <Label Content="abc" HorizontalAlignment="Center" Margin="0,54,0,87" Name="intro_lbl" VerticalAlignment="Center" Grid.Column="1" Padding="5" HorizontalContentAlignment="Center" Height="28" IsEnabled="False" />
                 </Grid>
            </xctk:WizardPage.Content>
        </xctk:WizardPage>
        <xctk:WizardPage Name="Second_Page" Title="DFG" Description="dfg" NextPage="{Binding ElementName=Last_Page}">
            <xctk:WizardPage.Content>
                <Grid Name="grid">
                    <TextBox Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Name="txt_second" VerticalAlignment="Center" />
                </Grid>
            </xctk:WizardPage.Content>
        </xctk:WizardPage>
        <xctk:WizardPage Name="Last_Page" PageType="Interior"
                         Title="Last Page"
                         Description="This is the last page in the process"
                         CanFinish="True" />
    </xctk:Wizard>
</Window>

【问题讨论】:

  • 我知道我过去曾看到它们为我显示,但我对您的设置了解得不够多,无法评论为什么它们不会为您显示。
  • 如果我理解正确,您想通过设计器向表单添加控件吗?所有控件,甚至来自其他库的控件都必须在工具箱中。
  • @Vitaliy 不,我知道如何让控件显示在工具箱中。我希望它们实际上在设计器窗口中显示,而不是完全空白且无法通过单击选择。
  • @Kilazur 嗯,他们必须在没有一些动作的情况下显示......我认为这个库有问题
  • 你可以试试wpf工具包

标签: c# wpf xaml wpftoolkit visual-studio-designer


【解决方案1】:

我知道这个答案来晚了,但昨天我被这个问题绊倒了,也许它对其他登陆这里的人有用。

我通过创建一个从WizardPage 派生的自己的控件来解决它。 只需创建一个新的 UserControl,包括 Xceed.Wpf.Toolkit 命名空间,并将 xaml 文件和代码隐藏文件中的类型从 UserControl 更改为 xctk:WizardPage

<xctk:WizardPage x:Class="WizardTest.MyWizardPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
             xmlns:local="clr-namespace:WizardTest"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
  <Grid>
    <TextBlock>Hello World!</TextBlock>
  </Grid>
</xctk:WizardPage>

现在您可以使用 VisualStudio 设计器创建您的 UI。 要将页面放入向导中,只需将派生页面的对象放入其项目中:

<xctk:Wizard>
  <local:MyWizardPage Title="My Wizard Page"/>
</xctk:Wizard>

您可以立即在您的服装页面中使用Bindungs,因为MyWizardPage 对象的DataContext 自动设置为向导DataContext(如果未明确给出,则从窗口DataContext 继承)

【讨论】:

    猜你喜欢
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-07
    • 2017-03-17
    • 1970-01-01
    • 2022-10-06
    相关资源
    最近更新 更多