Z
Z
Zulkund2017-02-17 17:13:04
WPF
Zulkund, 2017-02-17 17:13:04

Adding elements dynamically in WPF?

Good afternoon! Tell me, is it possible in WPF to describe a complex element in a XAML construct, and then dynamically add it to the layout on a button click? The structure is like this:

<Border Width="Auto" Height="Auto" Visibility="{Binding ElementName=CRGD,Path=IsChecked,Converter={StaticResource boolToVisibilityConverter}}">
                <StackPanel>
                    <Button Margin="5 5 5 5" Background="{StaticResource ButtonGrad}">
                        <StackPanel Orientation="Vertical">
                            <TextBlock HorizontalAlignment="Center" Margin="5 5 5 5">Прибор</TextBlock>
                            <Image DockPanel.Dock="Top" Margin="5 5 5 5" Source="Pics\NoIm_150x150.bmp" Width="150" Height="Auto" ></Image>
                        </StackPanel>
                    </Button>
                    <Menu  Height="Auto" Width="Auto" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5 5 5 5">
                        <MenuItem x:Name="MGD" Width="170" Height="35" HorizontalAlignment="Center">
                            <MenuItem.Icon>
                                <Image Source="Pics\Down.ico" Margin="2 2 2 2"/>
                            </MenuItem.Icon>
                        </MenuItem>
                    </Menu>
                </StackPanel>
            </Border>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2017-02-17
@Zulkund

<ContentPresenter ContentTemplate="{...}" Content = "{Binding ....}"/>

https://msdn.microsoft.com/en-us/library/system.wi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question