0

I hope my English is good enough for you, to unterstand what I mean.

I have some Problems. I want to make a Responsive Design for my WPF-App with C# in Visual Studio.

At First I want to make a Design-Framework, like Bootrap or UIKit in CSS, but this is just an Experiment for myself.

I know there exist ResourceDirectory for "static" Design and I know I normally can't change the Design in these Files, but I don't know, if there exist a Solution for dynamic Variables and the same. As Alternative I thought I can the Design in the ApplicationResource, but i haven't actual tested, how good this Solution is. How do I Change Variables in the App.xaml.cs or an explicit ViewModel for that. Is it equal to all other Windows with ViewModel?

I have found a Responsive Design "Example" on Youtube, but I don't know how these Layouts works. Can someone explain it? And I don't want to use this Solution at all, because I want to use a Design like a Framework. Responsive Design for WPF

And there are some Questions above the Desgin-Technics itself:

  • Can Triggers stand alone, or have they to be, for example, in <Style.Triggers>

  • How do I get the content from the Button in the Child-Textblock -> How do I get the Content from the Button, if I have a Viewbox inside this Button -> Can I set this as Template with "Dynamic" Content

  • How do I Create a Template, who have multiple Templates and/or Styles in it. (Dependency Property), for Styles there Exist an Solution here. Classes for Styles

  • When I use a Converter, can I Change Variables directly, instead implement thousand of Trigger with constants, I want that the Setter Values are changeable with the Converter.

  • An additional Alternative, I wanted to set the ResourceDirectory in CompilerTime for Configurations, but is this in C# possible. I mean the name is Metaprogramming, but I don't know. Example like: Somebody don't want to use my Variables, but use other Configurations, so he set my Variables as new from him, to use his Configurations. Because the ResourceDirectory build one Time by Compiling, there have to be configurate in Compiler-Time I tought.

I hope you can help me to solve all this Problems.

All Code in ResourceDirectory, Alternative in ApplicationResource in App.xaml

Template for Button with Textblock and Viewbox

<ControlTemplate x:Key="Example">
        <Button>
            <Button.ContentTemplate>
                <DataTemplate>
                    <Viewbox>
                        <TextBlock Text="Content From Button"> Or Get Here Content From Button</TextBlock>
                    <!--// Like <TextBlock Text="{this.button.content}"/> //-->
                    </Viewbox>
                </DataTemplate>
            </Button.ContentTemplate>
        </Button>
    </ControlTemplate>

In Style / Style.Triggers to set an new Value in Resource Directory or in ApplicationResource

<Style x:Key="My_BTN" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>

<DataTrigger Binding="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType=Window},
                      Converter={x:Static local:Converter.Instance}, ConverterParameter=1400}" Value="true">
    <Setter Property="Background" Value="{x:Static local:Example.SomeValue}"/>
</DataTrigger>

</Style.Triggers>
</Style>

1 Answers1

0

So, I have fixed 3 Problems.

  1. I have found out, how I use the Button Properties in Triggern, so I think I don't need the Trigger who are stand alone. I have to use the Relative Source like at Point two. and for Converter:
<Style x:Key="BTN_Error" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}" >
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=ActualWidth, RelativeSource={RelativeSource Self}, Converter={x:Static local:IsGreaterThen.Instance}, ConverterParameter=20}" Value="true">
            <Setter Property="Height" Value="200"></Setter>
            <Setter Property="Background" Value="Red"></Setter>
            <Setter Property="Content" Value="{Binding Path=Content, RelativeSource={RelativeSource Self}}"></Setter>
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Viewbox>
                            <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Content}"></TextBlock>
                        </Viewbox>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
    <Setter Property="Height" Value="50"></Setter>
</Style>
  1. I can use the Content from a Button if I use the Datatemplate only. Like this:
    <DataTemplate x:Key="flex_font">
           <Viewbox>
               <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Content}"></TextBlock>
           </Viewbox>
    </DataTemplate>
  1. I Think I don't need the Multitemplates anymore, I can set the Template in Style with Setters. And if the Templates are DataTemplates they don't override the Styles before or after the integration of the Styles.
    <Style x:Key="BTN_Warning" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
         <Setter Property="Background" Value="Yellow"/>
         <Setter Property="BorderBrush" Value="Gold"/>
         <Setter Property="ContentTemplate" Value="{StaticResource flex_font}" />
    </Style>

So the most import question is still open. If I use a Converter, can I change the value like my first Post? And at Last I think, if I know how I use the App.xaml.cs to change Variables, in Runtime, there enough Solutions to make my Responsive Design Framework.

I think I would like change the Variables in the App.xaml.cs like this.

Class MyWindow: Window {

    // Use Constructor just as an Example
    public MyWindow(){
        // I Don't know how to call the App-Class correct
        // Blue for Change Color as an Example
        App.Variable = "Blue";
    }
}