Add control dynamically using material design WPF









up vote
0
down vote

favorite












I am new in WPF. One of my desktop application I want to use Material Design. I added MaterialDesign nuget package and implemented successfully.
Here I have a situation where I need to add a button or card on my button click. those are fully dynamic.
Can I add material design controls dynamically from C#?
Help me with example.



Thanks in advance










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am new in WPF. One of my desktop application I want to use Material Design. I added MaterialDesign nuget package and implemented successfully.
    Here I have a situation where I need to add a button or card on my button click. those are fully dynamic.
    Can I add material design controls dynamically from C#?
    Help me with example.



    Thanks in advance










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am new in WPF. One of my desktop application I want to use Material Design. I added MaterialDesign nuget package and implemented successfully.
      Here I have a situation where I need to add a button or card on my button click. those are fully dynamic.
      Can I add material design controls dynamically from C#?
      Help me with example.



      Thanks in advance










      share|improve this question













      I am new in WPF. One of my desktop application I want to use Material Design. I added MaterialDesign nuget package and implemented successfully.
      Here I have a situation where I need to add a button or card on my button click. those are fully dynamic.
      Can I add material design controls dynamically from C#?
      Help me with example.



      Thanks in advance







      wpf material-design-in-xaml






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 4:22









      Nirav.Bhatt

      43




      43






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I believe you might be using Material Design In XAML. Make sure to check out the demo project. It contains all the answers to common control usage.



          OPTION ONE.



          You would usually use the "ItemsControl" to load objects into view dynamically. The items control is linked to a items source in your back-end view model. The source should be of type ObservableCollection. When ever you feed items to this source, the ItemsControl will update and insert based on the template it's provided.



          Below is a basic short example.



          xaml



           <ItemsControl ItemsSource="Binding ItemsToLoad" Grid.IsSharedSizeScope="True" Margin="12 0 12 0">
          <ItemsControl.ItemTemplate>
          <DataTemplate>
          <Button>Hi</Button>
          </DataTemplate>
          </ItemsControl.ItemTemplate>
          </ItemsControl>


          I'm assuming you have a good understanding of bindings, so I wont be posting all the back end code.



          OPTION TWO



          programmatically



          Seeing as you mentioned that you want to do it programmatically, you could also just do this:



          Step 1 : Create a grid and set a layout for you to work with.



          <Grid x:Name="grid_Main">

          <Grid.ColumnsDefinition>
          <ColumnDefinition/>
          <ColumnDefinition/>
          </Grid.ColumnsDefinition>

          <Grid.RowDefinition>
          <RowDefinition/>
          <RowDefinition/>
          </Grid.RowDefinition>

          </Grid>


          Step 2: Code behind.



           private void AddControlToGrid()

          Button button = new Button();
          grid_Main.Children.Add(button );
          Grid.SetRow(button , 1); // 1 is row index
          Grid.SetColumn(button , 0);// 0 is column index



          Just a Note of the material design usage. You need to reference the lib before you can use it in your view.



          Like this :



          Add this to your application resources.



           <Application x:Class="demo_app.App"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:demo_app">
          <Application.Resources>
          <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
          <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
          <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
          <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
          </ResourceDictionary.MergedDictionaries>
          </ResourceDictionary>
          </Application.Resources>
          </Application>


          Add this ref to any view you need to use a material design control on.



          xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


          You can then use material design controls like this.



          <materialDesign:Card Width="200">
          <Grid>
          <!--Content-->
          </Grid>
          </materialDesign:Card>





          share|improve this answer






















          • Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
            – Nirav.Bhatt
            Nov 10 at 14:48

















          up vote
          0
          down vote



          accepted










          I took reference with following link for a solution with material design.
          How to generate WPF controls automatically based on XML file?
          I don't know if this way is efficient for using in material design or not but I succeed in getting result for Card control.



           StackPanel stackPanel = new StackPanel();
          MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
          StringBuilder sb = new StringBuilder();

          //Create card
          sb.Append(@"<materialDesign:Card xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes' Background='#03a9f4' Foreground = 'DynamicResource PrimaryHueDarkForegroundBrush' Padding = '0' Width = '200'> ");
          sb.Append(@"<Grid><Grid.RowDefinitions><RowDefinition Height='Auto' /><RowDefinition Height = 'Auto' /><RowDefinition Height = 'Auto' /></Grid.RowDefinitions> ");
          sb.Append(@"<TextBlock Grid.Row='0' Margin = '16 16 16 4' Style = 'StaticResource MaterialDesignHeadlineTextBlock'> Call Jennifer </TextBlock><Separator Grid.Row = '1' Style = 'StaticResource MaterialDesignLightSeparator' /><TextBlock Grid.Row = '2' Margin = '16 0 16 8' VerticalAlignment = 'Center' HorizontalAlignment = 'Left' Style = 'StaticResource MaterialDesignBody2TextBlock'> March 19, 2016 </TextBlock>");
          sb.Append(@"</Grid></materialDesign:Card>");

          card = (MaterialDesignThemes.Wpf.Card)XamlReader.Parse(sb.ToString());
          // Add created button to previously created container.
          stackPanel.Children.Add(card);
          this.Content = stackPanel;


          If we look closely,
          xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes'
          above properties are impotent to put when preparing new dynamic control.



          Result I got from above code Dynamic Material design control






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235969%2fadd-control-dynamically-using-material-design-wpf%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I believe you might be using Material Design In XAML. Make sure to check out the demo project. It contains all the answers to common control usage.



            OPTION ONE.



            You would usually use the "ItemsControl" to load objects into view dynamically. The items control is linked to a items source in your back-end view model. The source should be of type ObservableCollection. When ever you feed items to this source, the ItemsControl will update and insert based on the template it's provided.



            Below is a basic short example.



            xaml



             <ItemsControl ItemsSource="Binding ItemsToLoad" Grid.IsSharedSizeScope="True" Margin="12 0 12 0">
            <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Button>Hi</Button>
            </DataTemplate>
            </ItemsControl.ItemTemplate>
            </ItemsControl>


            I'm assuming you have a good understanding of bindings, so I wont be posting all the back end code.



            OPTION TWO



            programmatically



            Seeing as you mentioned that you want to do it programmatically, you could also just do this:



            Step 1 : Create a grid and set a layout for you to work with.



            <Grid x:Name="grid_Main">

            <Grid.ColumnsDefinition>
            <ColumnDefinition/>
            <ColumnDefinition/>
            </Grid.ColumnsDefinition>

            <Grid.RowDefinition>
            <RowDefinition/>
            <RowDefinition/>
            </Grid.RowDefinition>

            </Grid>


            Step 2: Code behind.



             private void AddControlToGrid()

            Button button = new Button();
            grid_Main.Children.Add(button );
            Grid.SetRow(button , 1); // 1 is row index
            Grid.SetColumn(button , 0);// 0 is column index



            Just a Note of the material design usage. You need to reference the lib before you can use it in your view.



            Like this :



            Add this to your application resources.



             <Application x:Class="demo_app.App"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:demo_app">
            <Application.Resources>
            <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            </Application.Resources>
            </Application>


            Add this ref to any view you need to use a material design control on.



            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


            You can then use material design controls like this.



            <materialDesign:Card Width="200">
            <Grid>
            <!--Content-->
            </Grid>
            </materialDesign:Card>





            share|improve this answer






















            • Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
              – Nirav.Bhatt
              Nov 10 at 14:48














            up vote
            0
            down vote













            I believe you might be using Material Design In XAML. Make sure to check out the demo project. It contains all the answers to common control usage.



            OPTION ONE.



            You would usually use the "ItemsControl" to load objects into view dynamically. The items control is linked to a items source in your back-end view model. The source should be of type ObservableCollection. When ever you feed items to this source, the ItemsControl will update and insert based on the template it's provided.



            Below is a basic short example.



            xaml



             <ItemsControl ItemsSource="Binding ItemsToLoad" Grid.IsSharedSizeScope="True" Margin="12 0 12 0">
            <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Button>Hi</Button>
            </DataTemplate>
            </ItemsControl.ItemTemplate>
            </ItemsControl>


            I'm assuming you have a good understanding of bindings, so I wont be posting all the back end code.



            OPTION TWO



            programmatically



            Seeing as you mentioned that you want to do it programmatically, you could also just do this:



            Step 1 : Create a grid and set a layout for you to work with.



            <Grid x:Name="grid_Main">

            <Grid.ColumnsDefinition>
            <ColumnDefinition/>
            <ColumnDefinition/>
            </Grid.ColumnsDefinition>

            <Grid.RowDefinition>
            <RowDefinition/>
            <RowDefinition/>
            </Grid.RowDefinition>

            </Grid>


            Step 2: Code behind.



             private void AddControlToGrid()

            Button button = new Button();
            grid_Main.Children.Add(button );
            Grid.SetRow(button , 1); // 1 is row index
            Grid.SetColumn(button , 0);// 0 is column index



            Just a Note of the material design usage. You need to reference the lib before you can use it in your view.



            Like this :



            Add this to your application resources.



             <Application x:Class="demo_app.App"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:demo_app">
            <Application.Resources>
            <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            </Application.Resources>
            </Application>


            Add this ref to any view you need to use a material design control on.



            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


            You can then use material design controls like this.



            <materialDesign:Card Width="200">
            <Grid>
            <!--Content-->
            </Grid>
            </materialDesign:Card>





            share|improve this answer






















            • Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
              – Nirav.Bhatt
              Nov 10 at 14:48












            up vote
            0
            down vote










            up vote
            0
            down vote









            I believe you might be using Material Design In XAML. Make sure to check out the demo project. It contains all the answers to common control usage.



            OPTION ONE.



            You would usually use the "ItemsControl" to load objects into view dynamically. The items control is linked to a items source in your back-end view model. The source should be of type ObservableCollection. When ever you feed items to this source, the ItemsControl will update and insert based on the template it's provided.



            Below is a basic short example.



            xaml



             <ItemsControl ItemsSource="Binding ItemsToLoad" Grid.IsSharedSizeScope="True" Margin="12 0 12 0">
            <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Button>Hi</Button>
            </DataTemplate>
            </ItemsControl.ItemTemplate>
            </ItemsControl>


            I'm assuming you have a good understanding of bindings, so I wont be posting all the back end code.



            OPTION TWO



            programmatically



            Seeing as you mentioned that you want to do it programmatically, you could also just do this:



            Step 1 : Create a grid and set a layout for you to work with.



            <Grid x:Name="grid_Main">

            <Grid.ColumnsDefinition>
            <ColumnDefinition/>
            <ColumnDefinition/>
            </Grid.ColumnsDefinition>

            <Grid.RowDefinition>
            <RowDefinition/>
            <RowDefinition/>
            </Grid.RowDefinition>

            </Grid>


            Step 2: Code behind.



             private void AddControlToGrid()

            Button button = new Button();
            grid_Main.Children.Add(button );
            Grid.SetRow(button , 1); // 1 is row index
            Grid.SetColumn(button , 0);// 0 is column index



            Just a Note of the material design usage. You need to reference the lib before you can use it in your view.



            Like this :



            Add this to your application resources.



             <Application x:Class="demo_app.App"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:demo_app">
            <Application.Resources>
            <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            </Application.Resources>
            </Application>


            Add this ref to any view you need to use a material design control on.



            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


            You can then use material design controls like this.



            <materialDesign:Card Width="200">
            <Grid>
            <!--Content-->
            </Grid>
            </materialDesign:Card>





            share|improve this answer














            I believe you might be using Material Design In XAML. Make sure to check out the demo project. It contains all the answers to common control usage.



            OPTION ONE.



            You would usually use the "ItemsControl" to load objects into view dynamically. The items control is linked to a items source in your back-end view model. The source should be of type ObservableCollection. When ever you feed items to this source, the ItemsControl will update and insert based on the template it's provided.



            Below is a basic short example.



            xaml



             <ItemsControl ItemsSource="Binding ItemsToLoad" Grid.IsSharedSizeScope="True" Margin="12 0 12 0">
            <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Button>Hi</Button>
            </DataTemplate>
            </ItemsControl.ItemTemplate>
            </ItemsControl>


            I'm assuming you have a good understanding of bindings, so I wont be posting all the back end code.



            OPTION TWO



            programmatically



            Seeing as you mentioned that you want to do it programmatically, you could also just do this:



            Step 1 : Create a grid and set a layout for you to work with.



            <Grid x:Name="grid_Main">

            <Grid.ColumnsDefinition>
            <ColumnDefinition/>
            <ColumnDefinition/>
            </Grid.ColumnsDefinition>

            <Grid.RowDefinition>
            <RowDefinition/>
            <RowDefinition/>
            </Grid.RowDefinition>

            </Grid>


            Step 2: Code behind.



             private void AddControlToGrid()

            Button button = new Button();
            grid_Main.Children.Add(button );
            Grid.SetRow(button , 1); // 1 is row index
            Grid.SetColumn(button , 0);// 0 is column index



            Just a Note of the material design usage. You need to reference the lib before you can use it in your view.



            Like this :



            Add this to your application resources.



             <Application x:Class="demo_app.App"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:demo_app">
            <Application.Resources>
            <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            </Application.Resources>
            </Application>


            Add this ref to any view you need to use a material design control on.



            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"


            You can then use material design controls like this.



            <materialDesign:Card Width="200">
            <Grid>
            <!--Content-->
            </Grid>
            </materialDesign:Card>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 11:23

























            answered Nov 10 at 10:49









            B.Spangenberg

            1079




            1079











            • Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
              – Nirav.Bhatt
              Nov 10 at 14:48
















            • Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
              – Nirav.Bhatt
              Nov 10 at 14:48















            Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
            – Nirav.Bhatt
            Nov 10 at 14:48




            Thanks for the reply. I am sorry if I didn't made clear point in my question. I followed this link and got answer stackoverflow.com/questions/4990624/…
            – Nirav.Bhatt
            Nov 10 at 14:48












            up vote
            0
            down vote



            accepted










            I took reference with following link for a solution with material design.
            How to generate WPF controls automatically based on XML file?
            I don't know if this way is efficient for using in material design or not but I succeed in getting result for Card control.



             StackPanel stackPanel = new StackPanel();
            MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
            StringBuilder sb = new StringBuilder();

            //Create card
            sb.Append(@"<materialDesign:Card xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes' Background='#03a9f4' Foreground = 'DynamicResource PrimaryHueDarkForegroundBrush' Padding = '0' Width = '200'> ");
            sb.Append(@"<Grid><Grid.RowDefinitions><RowDefinition Height='Auto' /><RowDefinition Height = 'Auto' /><RowDefinition Height = 'Auto' /></Grid.RowDefinitions> ");
            sb.Append(@"<TextBlock Grid.Row='0' Margin = '16 16 16 4' Style = 'StaticResource MaterialDesignHeadlineTextBlock'> Call Jennifer </TextBlock><Separator Grid.Row = '1' Style = 'StaticResource MaterialDesignLightSeparator' /><TextBlock Grid.Row = '2' Margin = '16 0 16 8' VerticalAlignment = 'Center' HorizontalAlignment = 'Left' Style = 'StaticResource MaterialDesignBody2TextBlock'> March 19, 2016 </TextBlock>");
            sb.Append(@"</Grid></materialDesign:Card>");

            card = (MaterialDesignThemes.Wpf.Card)XamlReader.Parse(sb.ToString());
            // Add created button to previously created container.
            stackPanel.Children.Add(card);
            this.Content = stackPanel;


            If we look closely,
            xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes'
            above properties are impotent to put when preparing new dynamic control.



            Result I got from above code Dynamic Material design control






            share|improve this answer
























              up vote
              0
              down vote



              accepted










              I took reference with following link for a solution with material design.
              How to generate WPF controls automatically based on XML file?
              I don't know if this way is efficient for using in material design or not but I succeed in getting result for Card control.



               StackPanel stackPanel = new StackPanel();
              MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
              StringBuilder sb = new StringBuilder();

              //Create card
              sb.Append(@"<materialDesign:Card xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes' Background='#03a9f4' Foreground = 'DynamicResource PrimaryHueDarkForegroundBrush' Padding = '0' Width = '200'> ");
              sb.Append(@"<Grid><Grid.RowDefinitions><RowDefinition Height='Auto' /><RowDefinition Height = 'Auto' /><RowDefinition Height = 'Auto' /></Grid.RowDefinitions> ");
              sb.Append(@"<TextBlock Grid.Row='0' Margin = '16 16 16 4' Style = 'StaticResource MaterialDesignHeadlineTextBlock'> Call Jennifer </TextBlock><Separator Grid.Row = '1' Style = 'StaticResource MaterialDesignLightSeparator' /><TextBlock Grid.Row = '2' Margin = '16 0 16 8' VerticalAlignment = 'Center' HorizontalAlignment = 'Left' Style = 'StaticResource MaterialDesignBody2TextBlock'> March 19, 2016 </TextBlock>");
              sb.Append(@"</Grid></materialDesign:Card>");

              card = (MaterialDesignThemes.Wpf.Card)XamlReader.Parse(sb.ToString());
              // Add created button to previously created container.
              stackPanel.Children.Add(card);
              this.Content = stackPanel;


              If we look closely,
              xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes'
              above properties are impotent to put when preparing new dynamic control.



              Result I got from above code Dynamic Material design control






              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                I took reference with following link for a solution with material design.
                How to generate WPF controls automatically based on XML file?
                I don't know if this way is efficient for using in material design or not but I succeed in getting result for Card control.



                 StackPanel stackPanel = new StackPanel();
                MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
                StringBuilder sb = new StringBuilder();

                //Create card
                sb.Append(@"<materialDesign:Card xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes' Background='#03a9f4' Foreground = 'DynamicResource PrimaryHueDarkForegroundBrush' Padding = '0' Width = '200'> ");
                sb.Append(@"<Grid><Grid.RowDefinitions><RowDefinition Height='Auto' /><RowDefinition Height = 'Auto' /><RowDefinition Height = 'Auto' /></Grid.RowDefinitions> ");
                sb.Append(@"<TextBlock Grid.Row='0' Margin = '16 16 16 4' Style = 'StaticResource MaterialDesignHeadlineTextBlock'> Call Jennifer </TextBlock><Separator Grid.Row = '1' Style = 'StaticResource MaterialDesignLightSeparator' /><TextBlock Grid.Row = '2' Margin = '16 0 16 8' VerticalAlignment = 'Center' HorizontalAlignment = 'Left' Style = 'StaticResource MaterialDesignBody2TextBlock'> March 19, 2016 </TextBlock>");
                sb.Append(@"</Grid></materialDesign:Card>");

                card = (MaterialDesignThemes.Wpf.Card)XamlReader.Parse(sb.ToString());
                // Add created button to previously created container.
                stackPanel.Children.Add(card);
                this.Content = stackPanel;


                If we look closely,
                xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes'
                above properties are impotent to put when preparing new dynamic control.



                Result I got from above code Dynamic Material design control






                share|improve this answer












                I took reference with following link for a solution with material design.
                How to generate WPF controls automatically based on XML file?
                I don't know if this way is efficient for using in material design or not but I succeed in getting result for Card control.



                 StackPanel stackPanel = new StackPanel();
                MaterialDesignThemes.Wpf.Card card = new MaterialDesignThemes.Wpf.Card();
                StringBuilder sb = new StringBuilder();

                //Create card
                sb.Append(@"<materialDesign:Card xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes' Background='#03a9f4' Foreground = 'DynamicResource PrimaryHueDarkForegroundBrush' Padding = '0' Width = '200'> ");
                sb.Append(@"<Grid><Grid.RowDefinitions><RowDefinition Height='Auto' /><RowDefinition Height = 'Auto' /><RowDefinition Height = 'Auto' /></Grid.RowDefinitions> ");
                sb.Append(@"<TextBlock Grid.Row='0' Margin = '16 16 16 4' Style = 'StaticResource MaterialDesignHeadlineTextBlock'> Call Jennifer </TextBlock><Separator Grid.Row = '1' Style = 'StaticResource MaterialDesignLightSeparator' /><TextBlock Grid.Row = '2' Margin = '16 0 16 8' VerticalAlignment = 'Center' HorizontalAlignment = 'Left' Style = 'StaticResource MaterialDesignBody2TextBlock'> March 19, 2016 </TextBlock>");
                sb.Append(@"</Grid></materialDesign:Card>");

                card = (MaterialDesignThemes.Wpf.Card)XamlReader.Parse(sb.ToString());
                // Add created button to previously created container.
                stackPanel.Children.Add(card);
                this.Content = stackPanel;


                If we look closely,
                xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:materialDesign='http://materialdesigninxaml.net/winfx/xaml/themes'
                above properties are impotent to put when preparing new dynamic control.



                Result I got from above code Dynamic Material design control







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 14:45









                Nirav.Bhatt

                43




                43



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235969%2fadd-control-dynamically-using-material-design-wpf%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20