小编cod*_*der的帖子

有没有办法只用C#构建DataTemplate

有没有办法构建一个DataTemplate而不使用已弃用的 FrameworkElementFactoryXamlReader.Load字符串解释方法来编码(相关问题)(另一个相关的)

DataTemplate dt = new DataTemplate();
StackPanel sp = new StackPanel();
ComboBox cellComboBox = new ComboBox() { Visibility = Visibility.Collapsed };
CheckBox cellCheckBox = new CheckBox() { Visibility = Visibility.Collapsed };

sp.Children.Add(cellComboBox);
sp.Children.Add(cellCheckBox);

// then add the stackpanel somehow?
Run Code Online (Sandbox Code Playgroud)

更新:为什么? 这适用于可能需要多年支持的新程序.XamlReader字符串在运行时解析有一些构造函数,方法,属性......感觉很糟糕.在FrameworkElementFactory已弃用了几个版本,但从来没有一个真正的替代品.

c# wpf datatemplate

23
推荐指数
1
解决办法
652
查看次数

为什么克隆的UIElement或FrameworkElement的样式丢失

我试图加载GridUIElementS和/或FrameworkElement该含有S StyleDataTrigger秒。

以下是一个简单的本机XAML,它可以按预期工作;在3个状态之间切换复选框可为矩形提供三种不同的样式(请参见底部的图像)。

<Grid
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:XamlVsLoad"
    mc:Ignorable="d"
    Height="450" Width="800">
    <CheckBox Name="MyCheck" IsChecked="True" Content="Checkbox" IsThreeState="True" Margin="10,10,0,0" Width="200"/>
    <Rectangle Height="100" Width="100" StrokeThickness="5" Margin="10,50,100,100">
        <Rectangle.Style>
            <Style TargetType="Rectangle">
                <Setter Property="Fill" Value="White"/>
                <Setter Property="Stroke" Value="Black"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=MyCheck, Path=IsChecked}" Value="True" >
                        <Setter Property="Fill" Value="Orange"/>
                        <Setter Property="Stroke" Value="Blue"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ElementName=MyCheck, Path=IsChecked}" Value="False" >
                        <Setter Property="Fill" Value="Blue"/>
                        <Setter Property="Stroke" Value="Orange"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Rectangle.Style>
    </Rectangle>
</Grid>
Run Code Online (Sandbox Code Playgroud)

它也可以当我相同的文本保存到一个文件和动态加载到WindowViewbox与XAML这样S:

<Grid.ColumnDefinitions> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml clone uielement

7
推荐指数
1
解决办法
171
查看次数

有没有办法在编译时实例化所有c ++模板大小?

下面的c ++/cli模板正在运行,但似乎应该有一种方法可以进一步概括模板或添加一个可以在编译时创建模板实例的帮助器.

想到像http://en.cppreference.com/w/cpp/utility/integer_sequence这样的东西可能有用,但需要帮助/实施者功能的一些帮助.

简化主要内容以演示所需语法与当前使用的语法:

int main(array<String^>^ args) {

    // the actual number of possible char lengths is sparse (generally)
    // but the API allows for 1-1024
    List<int>^ varList = gcnew List<int>();
    varList->Add(40);
    varList->Add(80);
    varList->Add(128);

    SortedList<int, List<String^>^>^ allStrings = gcnew SortedList<int, List<String^>^>();

    // want something like this, but the compiler complains that 
    // the template is invalid expectes compile-time constant expressions
    for each(int key in varList) {
        allStrings->Add(key, UpdateTest<key>());
    }

    // this works, but has 1024 lines of case …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++-cli

4
推荐指数
1
解决办法
408
查看次数

WPF ContentPresenter仅显示列表中的第一项

我正在尝试创建一个WPF应用程序,其中我有一个显示帐户列表的StackPanel.每个帐户的代码后面都有一个Account对象,存储在List结构中.我想将此数据绑定到我的WPF,但我不想要一个列表框.

相反,我为每个帐户摘要的显示方式定义了一个模板.然后我想将它们堆叠在StackPanel中并将其称为一天.

问题是数据绑定只从列表中获取第一个项目,就是这样.如何绑定它,以便有效地创建一个很好的格式化数据块的堆栈列表?

以下是相关的WPF代码:

<StackPanel Name="sp_AccountList" Margin="0,0,0,0" VerticalAlignment="Top">
    <StackPanel.Resources>
    <svc:AccountBalanceColorConverter x:Key="accountColorConverter" />
    <Style x:Key="AccountSummaryBackgroundGradient" TargetType="{x:Type StackPanel}">
    <!-- nice formatting code here -->
    </Style>
    <Style x:Key="AccountSummaryNameStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Padding" Value="10,0,0,0" />
        <Setter Property="FontSize" Value="18" />
        <Setter Property="Height" Value="20" />
        <Setter Property="FontFamily" Value="Cambria" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Background" Value="Transparent" />
    </Style>
    <Style x:Key="AccountSummaryBalanceStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Padding" Value="10,0,0,0" />
        <Setter Property="FontSize" Value="14" />
        <Setter Property="Height" Value="20" />
        <Setter Property="FontFamily" Value="Cambria" />
        <Setter Property="Background" Value="Transparent" />
    </Style>                    
    <ObjectDataProvider x:Key="accounts"
                        ObjectType="{x:Type …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datatemplate

1
推荐指数
1
解决办法
1957
查看次数

标签 统计

wpf ×3

c# ×2

datatemplate ×2

c++ ×1

c++-cli ×1

clone ×1

data-binding ×1

templates ×1

uielement ×1

xaml ×1