I populate my controls by binding them to a class, as in this example:
HttpResponseMessage response = await client.GetAsync("/api/Customer/" + txtNumber.Text);
response.EnsureSuccessStatusCode();
var customer = await response.Content.ReadAsAsync<Customer>();
this.DataContext = customer;
This works fine.
I also use the same controls as search criteria, ie. the data the user enters in any controls should be collected and sent back to the server to query the db.
Is there a simple way to collect this data or do I have to loop through the controls and do the collection myself?
This is the XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Model="clr-namespace:Server.DTO;assembly=Server.DTO" mc:Ignorable="d" x:Class="Client.Forms.Reference.DataForm"
Title="Preisstufe" Height="346" Width="459" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ScrollViewer.VerticalScrollBarVisibility="Disabled" ResizeMode="NoResize" Loaded="Window_Loaded">
<DockPanel LastChildFill="True">
<StatusBar x:Name="statusBar" DockPanel.Dock="Bottom" Height="20">
<StatusBarItem x:Name="statusBarItem" Content="" Height="20" VerticalAlignment="Top"/>
</StatusBar>
<Grid>
<Grid.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}"/>
</Grid.Background>
<Canvas>
<Label Content="Number:" HorizontalAlignment="Left" Margin="87,33,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtNumber" HorizontalAlignment="Left" Height="24" Margin="185,36,0,211" Text="{Binding Number, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="76" KeyDown="txtNumber_KeyDown"/>
<Label Content="Description:" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="87" Canvas.Top="62"/>
<TextBox x:Name="txtDescription" HorizontalAlignment="Left" Height="24" Margin="185,64,0,183" Text="{Binding Description, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="236"/>
<Label Content="Abbr:" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="87" Canvas.Top="91"/>
<TextBox x:Name="txtAbbr" HorizontalAlignment="Left" Height="24" Margin="185,93,0,154" Text="{Binding Abbr, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="75"/>
</Canvas>
</Grid>
</DockPanel>
</Window>
You should look into binding the controls to properties in the codebehind. This also works with TwoWay binding and would make your task much simpler. This is achieved in WPF using DependancyProperties
Related
Im trying to create a progress bar for one of my computer configuration scripts and I'd like to avoid adding a button or some kind of trigger to the GUI,
The script is powershell and for the GUI XAML:
<Window x:Name="BackUp_MAINWINDOW" x:Class="ProgressBarTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProgressBarTest"
mc:Ignorable="d"
Title="88%" Height="110" Width="510" Icon="C:\Users\rsosa012\Documents\Scripts\Powershell\ICOs\PwC.ico" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Top="0" FontFamily="Georgia" Margin="0,-1,0,0" FontSize="11" SnapsToDevicePixels="True" BorderThickness="0">
<Window.TaskbarItemInfo>
<TaskbarItemInfo Description="Progress" ProgressState="Indeterminate" ProgressValue="50"/>
</Window.TaskbarItemInfo>
<Grid>
<ProgressBar HorizontalAlignment="Left" Height="17" Margin="10,44,0,0" VerticalAlignment="Top" Width="410" Value="50" Opacity="0.6"/>
<Image HorizontalAlignment="Left" Height="50" Margin="435,10,0,0" VerticalAlignment="Top" Width="50" Source="C:\Users\rsosa012\Documents\Scripts\Powershell\ICOs\PwC.ico"/>
<Label Content="Name: " HorizontalAlignment="Left" Height="20" Margin="10,6,0,0" VerticalAlignment="Top" Width="46" FontFamily="Georgia" Background="{x:Null}" Foreground="Black" FontSize="10" FontWeight="Bold"/>
<Label Content="Items remaining: " HorizontalAlignment="Left" Height="21" Margin="10,19,0,0" VerticalAlignment="Top" Width="110" FontFamily="Georgia" Background="{x:Null}" Foreground="Black" FontSize="10" FontWeight="Bold"/>
<TextBlock HorizontalAlignment="Left" Height="15" Margin="392,28,0,0" TextWrapping="Wrap" Text="88%" VerticalAlignment="Top" Width="28" FontSize="12" Opacity="0.6"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="51,12,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="62" FontSize="9"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="106,25,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="62" FontSize="9"/>
</Grid>
My question is about the events of these controls, does any of these controls have an event that triggers when the .showdialog() method executes, basically when the window appears?
Thanks in advance.
I have started learning wpf. I am trying to use line element but whenever i try to run this code line is not visible at all. Same case with rectangle, I have used rectangle element as well but it is also not showing up. What is the problem? I don't understand. I am able to see that in designer view but not in the runtime.
<Window x:Class="Mi_Express.Product_Details"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Mi_Express"
mc:Ignorable="d"
Title="Product_Details" Height="1920" Width="1080" WindowState="Maximized" ResizeMode="NoResize" WindowStyle="None"
Foreground="White" FontSize="30" FontWeight="Bold" Topmost="True" Background="White">
<Grid>
<Line HorizontalAlignment="Stretch" X1="10" Y1="10" X2="870" Y2="10" Stroke="Black" StrokeThickness="4" Margin="120,180,79,1712"/>
<Label Content="Shopping Cart:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="157,125,0,0" FontSize="30" FontWeight="DemiBold"/>
<Rectangle HorizontalAlignment="center" Height="73" Stroke="Black" StrokeThickness="3" VerticalAlignment="Top" Width="1017" Margin="28,1663,35,0"
/>
<Image HorizontalAlignment="Left" Height="102" VerticalAlignment="Top" Width="139" Margin="157,270,0,0"/>
<Button Content="Go Back" ClickMode="Press" Background="#FFE87E04" BorderBrush="#e87e04" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top" Width="174" Margin="157,1786,0,0" Height="61"/>
<Button Content="Continue" ClickMode="Press" Background="#e87e04" BorderBrush="#e87e04" FontSize="18" Foreground="white" HorizontalAlignment="Right" VerticalAlignment="Top" Width="160" Margin="0,1786,159,0" Height="61"/>
</Grid>
</Window>
The problem here is with the structure of your grid ..Dont apply margin to any of the UI elements over here.. instead remove it and use grid.column to position your UI elements..I have modified your code a litte
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Line Grid.Column="0" HorizontalAlignment="Stretch" X1="10" Y1="10" X2="870" Visibility="Visible" Y2="10" Stroke="Red" StrokeThickness="4" Margin="12,18,79,171"/>
<Label Grid.Column="1" Content="Shopping Cart:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="157,125,0,0" FontSize="30" FontWeight="DemiBold"/>
<Rectangle Grid.Column="2"
Visibility="Visible"
Fill="Blue"
HorizontalAlignment="center" Height="73" Stroke="Black" StrokeThickness="3" VerticalAlignment="Top" Width="1017" Margin="28,166,35,0"
/>
<Image HorizontalAlignment="Left" Height="102" VerticalAlignment="Top" Width="139" Margin="157,270,0,0"/>
<Button Content="Go Back" ClickMode="Press" Background="#FFE87E04" BorderBrush="#e87e04" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top" Width="174" Margin="157,1786,0,0" Height="61"/>
<Button Content="Continue" ClickMode="Press" Background="#e87e04" BorderBrush="#e87e04" FontSize="18" Foreground="white" HorizontalAlignment="Right" VerticalAlignment="Top" Width="160" Margin="0,1786,159,0" Height="61"/>
</Grid>
For more information on how to use grid in wpf .. please follow this links:
1) http://www.c-sharpcorner.com/UploadFile/1e050f/grid-layout-in-wpf/
2) http://www.wpf-tutorial.com/panels/grid-rows-and-columns/
3) https://wpftutorial.net/GridLayout.html
The problem is in the margin. Bottom margin is way too high and line goes out of the window
I guess you mistaken height with width and you ment Width="1920" Height="1080". Even so the actually height of the grid it would not be 1080, you can check it using this line
<Label Content="{Binding ElementName=grid,Path=ActualHeight}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="157,175,0,0" FontSize="30" FontWeight="DemiBold"/>
I have problem with having ScrollViewer working.
This is my MainWindow XAML:
<Window x:Class="Labels.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Labels"
mc:Ignorable="d"
Title="Labels" Height="350" Width="250" WindowStartupLocation="CenterScreen"
ResizeMode="NoResize" Background="#FFF6A300">
<ScrollViewer VerticalScrollBarVisibility="Hidden" Name="Scroll">
<Grid Margin="0,0,0,0" HorizontalAlignment="Center" Height="auto"
VerticalAlignment="Center" Name="mainGrid">
<Label x:Name="ProductLabel" Content="Product" HorizontalAlignment="Center"
Width="200" FontSize="16"
FontWeight="Bold" VerticalAlignment="Top"
HorizontalContentAlignment="Center" Margin="15,-5,9,0"/>
<TextBox x:Name="ProductTextBox" HorizontalAlignment="Center" Height="28"
Margin="13,22,11,0"
TextWrapping="Wrap" VerticalAlignment="Top" Width="200"
PreviewKeyDown="ProductTextBox_PreviewKeyDown"
SpellCheck.IsEnabled="True" FontSize="16"
HorizontalContentAlignment="Center"/>
<Label x:Name="IndexLabel" Content="Index: " HorizontalAlignment="Left"
Margin="10,50,0,0" VerticalAlignment="Top" Height="35" Width="62"/>
<Label x:Name="NameLabel" Content="Name:" HorizontalAlignment="Left"
Margin="10,80,0,0" VerticalAlignment="Top" Height="31" Width="62"/>
<TextBlock x:Name="IndexTextBlock" HorizontalAlignment="Left"
Margin="58,55,0,0" TextWrapping="Wrap" VerticalAlignment="Top"
Width="156" Height="23"/>
<TextBlock x:Name="NameTextBlock" HorizontalAlignment="Left"
Margin="58,85,0,0" TextWrapping="Wrap" VerticalAlignment="Top"
Width="155" Height="52"/>
<Label x:Name="TypeLabel" Content="Label template:"
HorizontalAlignment="Center" VerticalAlignment="Top" Height="30"
Width="199" FontSize="16" FontWeight="Bold"
Margin="15,142,10,0" HorizontalContentAlignment="Center"/>
<TextBox x:Name="TypeTextBox" HorizontalAlignment="Center"
Height="29" Margin="15,172,9,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="200"
PreviewKeyDown="TypeTextBox_PreviewKeyDown"
HorizontalContentAlignment="Center" FontSize="16"/>
<Label x:Name="CountLabel" Content="Print Copies: " HorizontalAlignment="Center"
Margin="14,206,10,0"
VerticalAlignment="Top" Height="31" Width="200" FontSize="16"
FontWeight="Bold" HorizontalContentAlignment="Center"/>
<TextBox x:Name="CountTextBox"
PreviewTextInput="CountTextBox_PreviewTextInput"
HorizontalAlignment="Center"
Height="28" Margin="13,232,11,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="200"
PreviewKeyDown="CountTextBox_PreviewKeyDown"
HorizontalContentAlignment="Center" FontSize="16"/>
<Label x:Name="LogoLabel" Content="Label" HorizontalAlignment="Left"
Margin="93,268,0,-8" VerticalAlignment="Top" Visibility="Hidden"/>
</Grid>
</ScrollViewer>
In code behind, I'm adding TextBox under LogoLabel and then I'm updating ScrollViewer's Layout like this:
mainGrid.Children.Add(nameTxt);
LogoLabel.Visibility = Visibility.Visible;
CountTextBox.IsEnabled = false;
nameTxt.Focus();
Scroll.UpdateLayout();
Scroll.ScrollToVerticalOffset(nameTxt.Margin.Top);
It looks like this:
As you can see on screenshoot uploaded above, I don't know how to make ScrollViewer to scroll that I could see entire LogoTextBox height. How to do it ? Any suggestions ?
You should scroll to a point outside of visible bounds. The Scroll.ScrollToVerticalOffset(nameTxt.Margin.Top) is already visible so no need to scroll.
You can try something like this:
Scroll.ScrollToVerticalOffset(nameTxt.Margin.Top + nameTxt.Height);
By doing this the scroll control will scroll to show the full text box.
The problem is with mainGrid height. It was set to auto. I changed it to static and in code I increase it's height by nameTxt height. And it works.
I'm starting to learn a little bit of WPF and Mahapps.metro, so I'm pretty new with those ones; here the question:
I have a button and two textboxes, the textboxes visibility is hidden when the forms loads, so when the user clicks the button, the textboxes visibility will be visible, but I want the textboxes to appear with that "slide" animation of the form load that Mahapps provides with the MetroWindow.
I tried using TransitioningContentControl but I couldn't make it happen. I would really appreciate your help, thanks.
My XAML:
<Controls:MetroWindow x:Class="practicas.nuevo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:practicas"
mc:Ignorable="d"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:behaviours="clr-namespace:MahApps.Metro.Behaviours;assembly=MahApps.Metro"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Reporte Nuevo" Height="300" Width="574.444" Loaded="formload">
<Controls:MetroWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Purple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Controls:MetroWindow.Resources>
<Grid>
<Controls:TransitioningContentControl x:Name="transitioning" Transition="Down"/>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="238,89,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="95" Margin="345,51,0,0" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Width="211" Controls:TextBoxHelper.Watermark="Hi Im a watermark" Background="#FF7400FF"/>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="95" Margin="0,51,0,0" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Width="211" Controls:TextBoxHelper.Watermark="Hi im another watermark" Background="#FF7400FF"/>
</Grid>
</Controls:MetroWindow>
EDIT: This method gave me the solution, the only difference is that the control that I used was ContentControl instead of StackPanel, here is my xaml for anyone who wants to make something like this:
P.S: Marked as an answer, thanks man.
<Controls:TransitioningContentControl x:Name="transitioning" Transition="Left">
</Controls:TransitioningContentControl>
<Controls:TransitioningContentControl x:Name="transitioning2" Transition="Up">
</Controls:TransitioningContentControl>
<Controls:TransitioningContentControl x:Name="transitioning3" Transition="Up">
</Controls:TransitioningContentControl>
<ContentControl x:Name="panel" Margin="-10,0,0,0" Visibility="Hidden">
<Canvas x:Name="canvas">
<Label x:Name="label" Content="Reporte Recibido:" Canvas.Left="10" Canvas.Top="41" Width="112"/>
<Label x:Name="label2" Content="Acciones a tomar:" Canvas.Left="600" Canvas.Top="41" Background="{x:Null}" RenderTransformOrigin="0.497,0.551"/>
<Controls:ToggleSwitch x:Name="ToggleSwitch" Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" Canvas.Left="284" Canvas.Top="122" OnLabel="Confirmado" OffLabel="Por Confirmar" RenderTransformOrigin="0.5,0.5" Visibility="Hidden" Width="140" Checked="switched" Unchecked="unswitched" />
<Image x:Name="accion" Height="25" Width="33" Canvas.Left="671" Canvas.Top="218" Source="Imagenes/Add-New.png" MouseDown="accionagregar"/>
<RichTextBox x:Name="RichTextbox1" HorizontalAlignment="Left" Height="154" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Width="284" Canvas.Left="438" Canvas.Top="64" TextChanged="textchanged" RenderTransformOrigin="0.815,0.541" Background="#FF7400FF" GotFocus="focus">
<xctk:RichTextBoxFormatBarManager.FormatBar >
<xctk:RichTextBoxFormatBar />
</xctk:RichTextBoxFormatBarManager.FormatBar>
<FlowDocument/>
</RichTextBox>
<RichTextBox x:Name="RichTextbox2" Background="#FF7400FF" Canvas.Top="64" GotFocus="reportefocus" Height="154" Width="274" Canvas.Left="5">
<xctk:RichTextBoxFormatBarManager.FormatBar >
<xctk:RichTextBoxFormatBar />
</xctk:RichTextBoxFormatBarManager.FormatBar>
<FlowDocument/>
</RichTextBox>
<Rectangle x:Name="reporteimagen" HorizontalAlignment="Left" Height="100" Margin="83,99,0,0" VerticalAlignment="Top" Width="100">
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_book_open_text}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle x:Name="accionesimagen" HorizontalAlignment="Left" Height="100" Margin="536,99,0,0" VerticalAlignment="Top" Width="100" >
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_book_list}"/>
</Rectangle.Fill>
</Rectangle>
<xctk:DateTimePicker x:Name="datetime" Width="162" Canvas.Left="504" Canvas.Top="218" Foreground="White" Format="Custom" FormatString="hh:mm tt" TimeFormat="Custom" TimeFormatString="hh:mm tt" CultureInfo="es-GT" ShowDropDownButton="False" Text="DefaultValue" IsReadOnly="True"/>
<Image x:Name="image7" Height="27" Canvas.Left="697" Canvas.Top="6" Width="33" Source="Imagenes/Repeat-All.png" RenderTransformOrigin="0.471,0.596" ToolTip="Reiniciar" MouseDown="reiniciar" Visibility="Hidden"/>
</Canvas>
</ContentControl>
<ContentControl x:Name="panel2" Visibility="Hidden">
<Canvas>
<Label x:Name="label5" Content="Reporte Creado Por:" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Canvas.Left="18" Canvas.Top="329" Background="{x:Null}" RenderTransformOrigin="0.497,0.551" Width="128"/>
<Label x:Name="label6" Content="Correlativo" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Canvas.Left="305" Canvas.Top="329" Background="{x:Null}" RenderTransformOrigin="0.497,0.551" Width="128"/>
<Label x:Name="label7" Content="Creado En:" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Canvas.Left="592" Canvas.Top="329" Background="{x:Null}" RenderTransformOrigin="0.497,0.551" Width="128"/>
<TextBox x:Name="textBox3" Height="23" HorizontalContentAlignment="Center" Canvas.Left="305" Canvas.Top="355" Width="128" IsReadOnly="True" Controls:TextBoxHelper.Watermark="Se genera al concluir."/>
<TextBox x:Name="textBox4" Height="23" HorizontalContentAlignment="Center" Canvas.Left="18" Canvas.Top="355" Width="128" IsReadOnly="True"/>
<TextBox x:Name="textBox5" Height="23" HorizontalContentAlignment="Center" Canvas.Left="592" Canvas.Top="355" Width="128" IsReadOnly="True"/>
<Image x:Name="image1" Height="44" Canvas.Left="504" Canvas.Top="337" Width="51" Source="Imagenes/Mail-Send.png" MouseDown="enviar" Visibility="Hidden"/>
<Image x:Name="image2" Height="44" Canvas.Left="225" Canvas.Top="337" Width="51" Source="Imagenes/User-Add.png"/>
<Image x:Name="image3" Height="44" Canvas.Left="169" Canvas.Top="337" Width="51" Source="Imagenes/Recycle-Bin.png" MouseDown="cancelar"/>
<Image x:Name="image5" Height="44" Canvas.Left="443" Canvas.Top="337" Width="51" Source="Imagenes/Lock.png"/>
<Image x:Name="image4" Height="44" Canvas.Left="443" Canvas.Top="337" Width="51" Source="Imagenes/Lock-Open.png"/>
</Canvas>
</ContentControl>
Example
You didn't place any content inside the transitioning content control. Try this:
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="238,89,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<Controls:TransitioningContentControl x:Name="transitioning" Transition="Down">
<StackPanel>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="95" Margin="345,51,0,0" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Width="211" Controls:TextBoxHelper.Watermark="Hi Im a watermark" Background="#FF7400FF"/>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="95" Margin="0,51,0,0" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Width="211" Controls:TextBoxHelper.Watermark="Hi im another watermark" Background="#FF7400FF"/>
</StackPanel>
</Controls:TransitioningContentControl>
</Grid>
Plus, reading the documentation, you'll see TransitioningContentControl performs the animation when the content changes. So you want to start with empty Transitioning Content Control, and then inside your Button click handler, set TransitioningContentControl Content dynamically to the two textboxes (need to be wrapped inside another control, like StackPanel, because transitioning control can only have a single child content.
Animations in WPF are quite tricky to pull of. I've made a fade animation a while back and it was quite a lot of work. Such a slide animation would require a lot of code and debugging to get it right. My recommendation is use a free slide animation library, and if you are feeling up to the task, you might be able to get a hold of some source code that you can use for inspiration if you want.
New to wpf applications. I tried to implement this code but the label is always blank no matter what I enter in the textbox:
<Window x:Class="Mufu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Muf(u)" Height="350" Width="525">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="100,200,0,0" Name="textBox3" VerticalAlignment="Top" Width="124" />
<Label Content="{Binding ElementName=textbox3, Path=Text}" Height="48" HorizontalAlignment="Center" Margin="0,30,0,0" Name="label4" VerticalAlignment="Top" Width="445" FontSize="26" />
</Grid>
That is because textbox3 and textBox3 are different names. Just change the case and it will work
<Stackpanel>
<TextBox Height="23" HorizontalAlignment="Left" Margin="100,200,0,0" Name="textBox3" VerticalAlignment="Top" Width="124" />
<Label Content="{Binding ElementName=textbox3, Path=Text}" Height="48" HorizontalAlignment="Center" Margin="0,30,0,0" Name="label4" VerticalAlignment="Top" Width="445" FontSize="26" />
</Stackpanel>