Results 1 to 1 of 1

Thread: transcode regular WPF application into a MVVM

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Posts
    10

    transcode regular WPF application into a MVVM

    Hi,

    I am new to MVVM concept and i would like to figure out how to transcode the regular examples I found around the internet into MVVM coding style.

    Therefore I will present you a simple example of xaml along with some behind code and I would appriciate if someone could transocode it into MVVM by giving some basic explanation.

    XAML code:

    Code:
    <Window x:Class="Misc_controls.SliderValueChangedSample"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="SliderValueChangedSample" Height="200" Width="300">
        <StackPanel Margin="10" VerticalAlignment="Center">
            <DockPanel VerticalAlignment="Center" Margin="10">
                <Label DockPanel.Dock="Left" FontWeight="Bold">R:</Label>
                <TextBox Text="{Binding ElementName=slColorR, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40" />
                <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slColorR" ValueChanged="ColorSlider_ValueChanged" />
            </DockPanel>
    
            <DockPanel VerticalAlignment="Center" Margin="10">
                <Label DockPanel.Dock="Left" FontWeight="Bold">G:</Label>
                <TextBox Text="{Binding ElementName=slColorG, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40" />
                <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slColorG" ValueChanged="ColorSlider_ValueChanged" />
            </DockPanel>
    
            <DockPanel VerticalAlignment="Center" Margin="10">
                <Label DockPanel.Dock="Left" FontWeight="Bold">B:</Label>
                <TextBox Text="{Binding ElementName=slColorB, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40" />
                <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slColorB" ValueChanged="ColorSlider_ValueChanged" />
            </DockPanel>
        </StackPanel>
    </Window>
    Code behind:


    Code:
    Imports System.Windows
    Imports System.Windows.Media
    
    Namespace Misc_controls
        Partial Public Class SliderValueChangedSample
            Inherits Window
            Public Sub New()
                InitializeComponent()
            End Sub
    
            Private Sub ColorSlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double))
                Dim color__1 As Color = Color.FromRgb(CByte(slColorR.Value), CByte(slColorG.Value), CByte(slColorB.Value))
                Me.Background = New SolidColorBrush(color__1)
            End Sub
        End Class
    End Namespace
    Thanks in advance!

    spyMag
    Last edited by spymag; Oct 3rd, 2015 at 05:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width