DEV Community

loading...

WPF A Refresher

jwp profile image John Peters ・2 min read

My current project may include some WPF work. I had to brush up on it a bit, but love the new hot reload feature.

I always preferred the Dark Theme but couldn't recall how to use it.

Alt Text

Oh yes, the Resource Directory thing.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Themes\ExpressionDark.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Enter fullscreen mode Exit fullscreen mode

This means the project has a themes folder with ExpressionDark.xaml.

Alt Text

But we had to use Nuget to get the theme.

Alt Text

I remember this persons' name from 7 years ago. Glad to see package is still there. Wow! Thanks Stan...

Then I needed to recall the use of StackPanel, Grid, RowDefinition, Button, Label and TextBox.

<StackPanel  Background="#333">      
<Grid  Margin="50,20" >
    <Grid.RowDefinitions>
        <RowDefinition ></RowDefinition>
        <RowDefinition ></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Height="30" Orientation="Horizontal" HorizontalAlignment="Left">
        <Button Width="120">Best Article</Button>
        <Button Width="120">Best Project</Button>
        <Button Width="120">GitHub</Button>
        <Button Width="120">StackOverFlow</Button>
        <Button Width="120">MSDN</Button>
        <Button Width="120">Azure</Button>
    </StackPanel>
    <Grid Grid.Row="1" Height="30" Margin="0,10" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40"></ColumnDefinition>
                <ColumnDefinition Width="400"></ColumnDefinition>
                <ColumnDefinition Width="150"></ColumnDefinition>
            </Grid.ColumnDefinitions>
        <Label Grid.Column="0" HorizontalContentAlignment="center" Margin="0,0,20,0">URL</Label>
        <TextBox Grid.Column="1">https://dev.to</TextBox>
        <Button Click="ButtonGo" Margin="15 0 0 0" Grid.Column="2">Go</Button>
    </Grid>
</Grid>
</StackPanel>
Enter fullscreen mode Exit fullscreen mode

Button Click Handlers, Margins and Grid Column Placement

 <Button Click="ButtonGo" Margin="15 0 0 0" Grid.Column="2">
Enter fullscreen mode Exit fullscreen mode

And off we go...

JWP2021 WPF

Discussion (0)

pic
Editor guide