set ItemsPanelTemplate grid position to StatusBarItem programmatically

61 views Asked by At

How can i set the grid position to my StatusBarItems programatically?

I have the following StatusBar and now i want to set the position of the StatusBarItems in my ViewModel .

<StatusBar ItemsSource="{Binding StatusBarItemsSource}" DockPanel.Dock="Bottom" >
    <StatusBar.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="100" />
                </Grid.ColumnDefinitions>
            </Grid>
        </ItemsPanelTemplate>
    </StatusBar.ItemsPanel>
</StatusBar>

I want my logo in the third column but this won't work :/

StatusBarItem logo = new StatusBarItem
{
    Content = new Image
    {
        Source = new BitmapImage(new Uri("Logo.ico", UriKind.Relative)),
        Width = 16,
        Height = 16
    }
    Grid.Column = 3
};
StatusBarItemsSource.Add(logo);
1

There are 1 answers

0
mm8 On BEST ANSWER

Use the Grid.SetColumn method to set the Grid.Column attached property of the StatusBarItem to 2:

StatusBarItem logo = new StatusBarItem
{
    Content = new Image
    {
        Source = new BitmapImage(new Uri("logo.ico", UriKind.Relative)),
        Width = 16,
        Height = 16
    }
};
Grid.SetColumn(logo, 2);
StatusBarItemsSource.Add(logo);