Wpf Material Design Date-Picker Theme - wpf

I can successfully build the date picker with the code below.
<Button x:Name="ButtonOpenDialog" Content="..." IsEnabled="True"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" CommandTarget="{Binding ElementName=PopupAddCustom}"/>
<materialDesign:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False"
materialDesign:DialogHost.DialogOpenedCallback="CalendarDialogOpenedEventHandler"
materialDesign:DialogHost.DialogClosingCallback="CalendarDialogClosingEventHandler">
<materialDesign:DialogHost.DialogContent>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,-2,0,2">
<Calendar x:Name="MaterialCalendar" Margin="-1 -4 -1 0" IsTodayHighlighted="False" SelectedDatesChanged="MaterialCalendar_SelectedDatesChanged"/>
</StackPanel>
<StackPanel Grid.Row="1" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsDefault="True" Margin="20 0"
CommandParameter="1" >OK</Button>
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsCancel="True"
CommandParameter="0" >CANCEL</Button>
</StackPanel>
</Grid>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
But I want to change foreground color and background color.As shown:
Header Background Color To => Gray
Header Text Foreground Color To => White
Icon Color To => White
Month Text Foreground Color To => White
Main Background Color To => Black
Main TextForeColor To => White
How can I do that? Is it possible to change without changing original source?

You could set the Background property of the Calendar to Black and override two resources:
<Calendar x:Name="MaterialCalendar" Margin="-1 -4 -1 0"
IsTodayHighlighted="False"
Background="Black">
<Calendar.Resources>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="Gray" />
<SolidColorBrush x:Key="MaterialDesignBody" Color="White" />
</Calendar.Resources>
</Calendar>

Related

WPF Canvas as content inside button is not visible if adjacent element fills the space inside a container (DockPanel, Grid)

I have a button like so:
<StackPanel Orientation="Vertical" Width="200">
<DockPanel LastChildFill="False">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" />
<Button Width="120" DockPanel.Dock="Left">
<Grid>
<TextBlock Text="Button" ></TextBlock>
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</Grid>
</Button>
</DockPanel>
</StackPanel>
In this case the canvas content will not get rendered and it's content won't be visible.
If I however change the Grid lengths from 81 to 80 it works.
It will also work in this scenario:
<Grid Width="200">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" HorizontalAlignment="Right" Grid.Column="1" />
<Button Width="120" HorizontalAlignment="Left">
<Grid>
<TextBlock Text="Button" ></TextBlock>
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</Grid>
</Button>
</Grid>
The Canvas will also work if not inside a button:
<StackPanel Orientation="Vertical" Width="200">
<DockPanel LastChildFill="False" Height="42">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" />
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</DockPanel>
</StackPanel>
Why is it behaving like that inside a button? How can be this fixed to the wanted behavior of showing the canvas?

Set up a footer that stays in the footer area when resize WPF application

I am struggling to set up a footer in a WPF application. I want my footer to be a simple text and nothing more and I want it to stay still when resizing the page. The page contains a menu on in the top, a button, that is put into a canvas because I don't want it to change its size. I also have a textBox that is in a grid and I want it to be resized with the page. Under the textBox I want to setup the footer (I set it up with a label). Can anybody tell me how can I achieve this ? I tried everything ..
Here is the main part of my .XAML file:
<Grid>
<Menu>
<MenuItem Header="_File">
<MenuItem Header="_Exit" Command="{Binding x}"/>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="Logs" Comm`enter code here`and="{Binding y}" />
</MenuItem>
</Menu>
<Canvas Margin="0,0,-0.4,432.6">
<Button Command="{Binding z}" Name="Button" Canvas.Top="22" Width="122" Height="24" Canvas.Left="10">Download Images</Button>
</Canvas>
<Canvas Margin="0,0,-0.4,432.6">
<Label HorizontalAlignment="Left" Width="108" Canvas.Left="10" Height="25" Canvas.Top="47">Status</Label>
</Canvas>
<TextBox Name="MessageDisplay" Text="{Binding q, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,IsAsync=True}" Margin="10,73,10.6,44.6"/>
<Label Margin="0,475,-0.4,-0.4">Footer !!!</Label>
</Grid>
This is how it looks when I run the app:
Before any resize
and this is what happens after I maximize the page :
maximized
You should be making use of RowDefinitions for your Grid to do this reliably. Don't set canvas postions and margins to specific areas or your resizing will never look right. Margin is a great tool, but it should be set in the scope of the area the control is in within the layout
Specify your row definitions and their height. Here's an example using your code. Rows start at index 0. Take this example and look up some more information about specifying grid row and column layouts in WPF. This should get you started on the right path though.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Menu>
<MenuItem Header="_File">
<MenuItem Header="_Exit" Command="{Binding x}"/>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="Logs" />
</MenuItem>
</Menu>
<Canvas Grid.Row="1">
<Button Command="{Binding z}" Name="Button" Margin="5" Width="122" Height="24" >Download Images</Button>
</Canvas>
<Canvas Grid.Row="2">
<Label HorizontalAlignment="Left" Width="108" Height="25" >Status</Label>
</Canvas>
<TextBox Grid.Row="3" Name="MessageDisplay" Text="{Binding q, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,IsAsync=True}" Margin="5"/>
<Label Grid.Row="4" >Footer !!!</Label>
</Grid>

Make content inside Button responsive in WPF

I have vertical navigation bar. Each button of the navigation has it's own image and text. For now the image has static height set to Height="50"and text has the default value. When I resize the window the buttons grow responsive but the content inside keeps the same size.
This is how it look right now:
https://gyazo.com/48cff48437b66f462dccd23639dd59ac (GIF)
My XAML code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<UniformGrid Background="DodgerBlue" Grid.Column="1" Columns="1">
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/home-5-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Home</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/search-3-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Search</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/twitter-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Twitter</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/chat-4-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Chat</TextBlock>
</StackPanel>
</Button>
</UniformGrid>
</Grid>
How could i make content inside the Buttons responsive and grow when the button grows in XAML WPF?
Use Viewbox as shown here.
<Viewbox Stretch="Uniform">
<Button ... />
</Viewbox>

Event on ItemsControl issue [duplicate]

I`ve created big button which contains grid as below:
<Button Height="Auto" Width="Auto" Command="{Binding ContinueWithoutScan}" BorderThickness="0">
<Button.Template>
<ControlTemplate>
<Grid >
<TextBlock HorizontalAlignment="Center"
TextWrapping="Wrap" Text="Text"
VerticalAlignment="Center" FontWeight="DemiBold"
Height="Auto" Width="Auto"
FontSize="25" Foreground="White"/>
<materialDesign:PackIcon Height="Auto" Width="70" Kind="ChevronRight" Foreground="White"
VerticalAlignment="Center" HorizontalAlignment="Right"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
There is problem that only TextBlock inside Template is clickable. Does anyone know how do I make whole content clickable? I working with MVVM so I dont want make Grid.OnMouseEneter.
Is there option to do that of I have to use EventTriggers?
The Grid needs to have a Background other than the default null to receive input events. You may set a transparent background instead of null:
<Grid Background="Transparent">
...
</Grid>

WPF Image Button with text anchored at the bottom of the Button

I would like the text to be anchored to the very bottom of the button, regardless of the Image aspect ratio.
I would like the Image to stretch to fit the remaining space in the button.
This xaml does have the Image fill the remaining space, but the text is placed right under the Image rather that at the very bottom of the button. Maybe I need to use something other than a DockPanel, but I am not sure what to use. The text does not need to be in a Label if there is a different way to do it that works.
Thanks
<Button Height="150" Width="150">
<DockPanel LastChildFill="True">
<Label HorizontalContentAlignment="Center" DockPanel.Dock="Bottom">foo</Label>
<Image Source="bar.png" />
</DockPanel>
</Button>
The Button element does not automatically allow its content to fill the entire Button area. To do that, you'll have to set both the HorizontalContentAlignment and VerticalContentAlignment properties to "Stretch."
<Button Height="150" Width="150"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<DockPanel LastChildFill="True">
<Label HorizontalContentAlignment="Center" DockPanel.Dock="Bottom">foo</Label>
<Image Source="bar.png" />
</DockPanel>
</Button>
You most likely need to tell the DockPanel to expand to its Height to the parent container:
<Button x:Name="button" Height="150" Width="150">
<DockPanel LastChildFill="True" Height="{Binding Height, ElementName=button}">
<Image DockPanel.Dock="Top" Source="bar.png" />
<Label DockPanel.Dock="Bottom" HorizontalContentAlignment="Center"
VerticalAlignment="Bottom">foo</Label>
</DockPanel>
</Button>
Just did a quick experiment
Maybe this helps?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Image Source="bar.png" Stretch="UniformToFill" Grid.Row="0" />
<Label DockPanel.Dock="Bottom" Content="Foo" HorizontalAlignment="Center" Grid.Row="1" x:Name="Label1" VerticalAlignment="Bottom" ></Label>
</Grid>
In case try to adjust row heights.

Resources