相关疑难解决方法(0)

如何在代码中设置控制模板?

我在XAML中有这个

<ControlTemplate TargetType="{x:Type Button}">
    <Image ...>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我希望在C#代码中实现相同的功能.我怎样才能做到这一点?

ControlTemplate ct = new ControlTemplate();..
Image img = new Image();..
Run Code Online (Sandbox Code Playgroud)

现在如何将此图像分配给控制模板?我们能做到这一点还是我错过了这里的概念?

c# wpf xaml contentcontrol

30
推荐指数
2
解决办法
5万
查看次数

如何在代码中获取ListBox ItemsPanel

我有一个带有ItemsPanel的ListBox

<Setter Property="ItemsPanel">
    <Setter.Value>
        <ItemsPanelTemplate>
             <StackPanel x:Name="ThumbListStack" Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)

我想在后面的代码中使用TranslateTransform沿X轴移动堆栈面板.

问题是,我找不到Stack Panel.

ThumbListBox.FindName("ThumbListStack")
Run Code Online (Sandbox Code Playgroud)

什么都不返回 我想用它:

Storyboard.SetTarget(x, ThumbListBox.FindName("ThumbListStack"))
Run Code Online (Sandbox Code Playgroud)

如何获取堆栈面板,以便我可以将其与TranslateTransform一起使用

谢谢

.net c# wpf code-behind itemspanel

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

标签 统计

c# ×2

wpf ×2

.net ×1

code-behind ×1

contentcontrol ×1

itemspanel ×1

xaml ×1