小编Dav*_*mer的帖子

如何在WPF中获取组框中的控件列表

在标准的WinForms开发中,我将执行以下操作:

foreach (Control in groupBox1.Controls)
{
     MessageBox.Show(c.Name);
}
Run Code Online (Sandbox Code Playgroud)

一个人在WPF中如何做到这一点?我在GroupBox中有一个Grid和网格中的一些控件(按钮等),但似乎无法弄清楚如何获得每个控件.

.net c# wpf groupbox wpf-controls

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

将接口解析为UIElement(Unity,PRISM,C#)

使用PRISM时,使用unity来连接事物的正常方法是定义一个接口并使用此接口注册一个实现.现在,我对视图有疑问.场景很简单:

假设允许设置播放命令的自定义视频控件.该控件由简单的接口"IPlayControlView"定义.显而易见的问题是,当我解决此控件并尝试将其添加到a时StackPanel,它不起作用,因为我有一个IPlayControl,而不是一个UIElement.

我可以投它UIElement,因为我知道它是一个UIElement.但有没有更好的方法,比如

public interface IPlayControlView : UIElement
Run Code Online (Sandbox Code Playgroud)

这不起作用,但也许其他一些事情会起作用......

这是一个普遍的问题,如果我使用接口解析视图,我每次都会遇到这个问题.也许它不是它的方式,但我一直认为其中一个....好吧,只是有个主意.我将只使用一个属性UIElement扩展IPlayControl,并将其设置为对自身的引用.所以,没关系,问题在打字时回答:-)

如果有更好的方法,我总是喜欢学习新事物.也许是IUIElement?

克里斯

c# views interface unity-container uielement

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

如何绑定WPF中另一个程序集中的类的属性?

在WPF中,是否可以将其他程序集的类的属性绑定到不同程序集中的控件.请帮助.谢谢

wpf binding

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

在C#中通过Internet更新安全可靠的方式

什么是最安全,最安全的方式,允许软件自动更新,而无需打开太多漏洞,使黑客能够轻松访问系统?

c# security wpf auto-update

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

如何使WPF ListView项目水平和垂直重复?

我有一个ListView我希望水平显示的地方.这工作正常,但现在我需要让它们像Windows资源管理器类型一样显示.

例如 :

A   B   C

D   E   F

G   H   I
Run Code Online (Sandbox Code Playgroud)

要么

A   B

C   D

E   F

G   H

I
Run Code Online (Sandbox Code Playgroud)

有可能ListView吗?

wpf xaml templates listview

2
推荐指数
2
解决办法
2811
查看次数

选中时如何将焦点设置到TreeViewItem中的控件

我有一个TreeView项目由HierarchicalDataTemplates 定义.每个TreeViewItem创建的都有一些TextBoxes.当TreeViewItem选择我想设置键盘FocusTextBoxTreeViewItem(在TextBox其名称TextBox1).我怎样才能做到这一点?

wpf treeview focus treeviewitem

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

WPF,在InitializeComponent之后直接放置代码的不良做法?

我只是在想什么.我有一个加载页面的框架,目前每个页面都有一个Page_Loaded方法,每次访问页面时都会运行.这工作得很好,但如果我使用导航转到以前访问过的页面,我会注意到错误.返回页面后,Page_Loaded再次被调用,我不想要.

使用调试,我注意到InitializeComponent只有在第一次实现页面时才调用,并且想知道我是否可以Page_Loaded在调用之后简单地放入我的代码,如下所示:

public partial class MyPage: Page
{
    public MyPage()
    {
        InitializeComponent();
        //======> To Here
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
       //Put Code from here <======
    }
}
Run Code Online (Sandbox Code Playgroud)

这可以解决我的问题,但这是一个不好的做法?如果是这样,我可能会遇到什么问题?

谢谢,Kohan

c# wpf coding-style

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

如何获取WPF窗口控件集合

我尝试获取所有WPF窗口控件集合.换句话说,我尝试获得相同的结果,就像在win form app中一样:

form.Controls
Run Code Online (Sandbox Code Playgroud)

我想格式化SQL查询时使用这些控件的值.WPF窗口可以获得这样的控件集合吗?谢谢

wpf controls window

2
推荐指数
2
解决办法
6533
查看次数

仅在选择ListViewItem时显示内容

ListBoxListBoxItems我选择其中一个时,我想改变按钮"View"的可见性并显示它.意味着默认状态为隐藏.

这是可能的,如果是这样,我是用XAML中的触发器还是后面的代码解决这个问题?

XAML片

<ListBox Background="Transparent" 
      ItemContainerStyle="{StaticResource listBoxTemplate}" BorderThickness="0">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" VerticalAlignment="Center" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Background="Beige" Margin="10 10 10 10" 
                    HorizontalAlignment="Center" Width="500" Height="100"
                    VerticalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Name="TopRow" Height="50" />
                    <RowDefinition Name="BottomRow" Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Name="LeftSideMenu" Width="*"/>
                    <ColumnDefinition Name="Middle" Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Grid.Row="0" Content="{Binding name}" />

                <Button Grid.Column="1" VerticalAlignment="Center" 
                    Grid.RowSpan="2" Name="view" Click="viewClicked_Click"
                    Grid.Row="0">View</Button>

                <Label Grid.Column="0" Grid.Row="1" 
                    Content="{Binding description}" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

c# wpf listbox selecteditem

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

所选项目的列表框项目模板

我正在使用带有ItemTemplate的Listbox,当我从列表中选择一个项目时,它显示蓝色背景我如何设置所选项目的样式,类似于未选择的项目?

wpf listbox selecteditem itemtemplate

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