Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
C#
<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
C#
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
C#
public class Plugin
    {
        private String name_;

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




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>
Posted
Updated 17-Mar-16 11:41am
v6
Comments
Richard Deeming 17-Mar-16 14:52pm    
And we're expected to guess what "issue with the binding" means, are we?

Click "Improve question" and update your question with a proper description of the problem you're facing.

1 solution

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 ?
 
Share this answer
 
v2
Comments
Member 12330910 17-Mar-16 17:56pm    
The answer here : http://www.codeproject.com/Articles/32629/A-better-panel-for-data-binding-to-a-WrapPanel-in

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900