与wrappanel绑定 [英] Binding with wrappanel

查看:76
本文介绍了与wrappanel绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在学习WPF。我正在使用MahApps插件来设计我的GUI。

我想使用tiles面板为列表中的每个插件生成一个tile,但是我遇到了绑定问题。问题是瓷砖HELLO和HELLO2没有显示,我只看到1个没有文字的瓷砖



我尝试了什么:



MainView.xaml

Hi,

I'm learning WPF. I'm using MahApps plugin to design my GUI.
I want to use the tiles panel to generate a tile for each plugin in the list but I have an issue with the binding. The issue is the tiles "HELLO" and "HELLO2" are not displayed, I can see only 1 tile without a text

What I have tried:

MainView.xaml

<Grid>
   <Controls:MetroAnimatedTabControl x:Name="metroAnimatedTabControl" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="False" >
      <TabItem Header="" FontFamily="Segoe MDL2 Assets" ToolTip="DashBoard">
         <WrapPanel Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"DataContext="{Binding Plugins}">
            <Controls:Tile Title="{Binding Name}" removed="Navy" IsEnabled="True" FontFamily="Calibri">
            </Controls:Tile>
         </WrapPanel>
      </TabItem>

....





MainView.cs



MainView.cs

private List<Plugin> plugins_;
...
public MainWindow()
        {
            plugins_ = new List<Plugin>();

            Plugin toto = new Plugin();
            toto.Name = "HELLO";
            plugins_.Add(toto);

            Plugin toto2 = new Plugin();
            toto2.Name = "HELLO2";
            plugins_.Add(toto2);

            InitializeComponent();
...
}
...
 public List<Plugin> Plugins
        {
            get { return plugins_; }
        }







Plugin.cs




Plugin.cs

public class Plugin
    {
        private String name_;

        public string Name
        {
            get { return name_; }
            set { name_ = value; }
        }
    }









按照RickZeeland的样本,我写了这个但结果相同:





Following RickZeeland sample, I wrote this but same result :

    <Grid>
        <Controls:MetroAnimatedTabControl x:Name="metroAnimatedTabControl" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="False" >
            <TabItem Header="" FontFamily="Segoe MDL2 Assets" ToolTip="DashBoard">


                <ItemsControl x:Name="pluginsControl" Margin="10">
                    <ItemsControl.Template>
                        <ControlTemplate>
                            <WrapPanel  Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                        </ControlTemplate>
                    </ItemsControl.Template>
                    
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Controls:Tile Title="{Binding Path=Name,  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Plugin}}" removed="Navy" IsEnabled="True" FontFamily="Calibri">
                                <Grid>
                                    <Image Width="64" Height="64" RenderOptions.BitmapScalingMode="HighQuality"
                            Source="http://ezcomponents.org/images/logos/icon-64x64.png"></Image>
                                </Grid>
                            </Controls:Tile>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
...
 </Controls:MetroAnimatedTabControl>


    </Grid>

推荐答案

这看起来类似于你正试图实现:

从列表中填写WrapPanel (WPF)|发现.NET [ ^ ]



它使用 ItemsControl 来包含WrapPanel。



示例代码不正确,因为你注意到了,最好不要忘了它。

但是 ItemsControl 似乎还有很长的路要走,没有MahApps插件你试过吗?
This looks similar to what you are trying to achieve:
Fill WrapPanel from the list (WPF) | Discovering .NET[^]

It uses an ItemsControl to contain the WrapPanel.

The example code is not correct as you noticed, better forget about it.
But the ItemsControl seems the way to go, did you try it without the MahApps plugin ?


这篇关于与wrappanel绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆