I have a main application at this there are border different buttons. This also includes the "Einstellung" button. Pressing this button should display a different content than before. This I realized with a UserControl.
Now you can make settings in this user control and save them.
This saving I made in the Settings
and with the Code
Vorschau.Properties.Settings.Default.BreiteBitmap = Int32.Parse(tbBreiteBitmap.Text);
Vorschau.Properties.Settings.Default.HoeheBitmap = Int32.Parse(tbHoeheBitmap.Text);
Vorschau.Properties.Settings.Default.AnzahlKoordinaten = Int32.Parse(tbAnzahlKoordinaten.Text);
Now I press the "Speichern" button. He saves me the settings.
I now change the UserControl, so I click on a button "Vorschau" and a new content is displayed to me. If I now click again on "Einstellung" is the content still there, as I have stored it.
But the problem comes. I close the application and I open it again. Now I click on the button "Einstellung" in the textboxes is only everywhere a 0 in it.
This should not be so, but the content should be from there in the past.
I retrieve this content when I start the application. See the code snippet.
public UCEinstellung()
{
InitializeComponent();
//Lade der Einstellungen
tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
AND
public MainWindow()
{
InitializeComponent();
MouseDown += Window_MouseDown;
einstellung.tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
einstellung.tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
einstellung.tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
Unfortunately this does not work.
I hope you can tell me where the error lies. In another application WITHOUT usercontrol works, this store and retrieve properly.
UCEinstellung
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
namespace Vorschau
{
/// <summary>
/// Interaktionslogik für UCEinstellung.xaml
/// </summary>
public partial class UCEinstellung : UserControl
{
public UCEinstellung()
{
InitializeComponent();
//Lade der Einstellungen
tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
private static Boolean kontrolliereObZahl(String pText)
{
int zahl1;
double zahl2;
Boolean istZahl;
if (Int32.TryParse(pText, out zahl1) || Double.TryParse(pText, out zahl2))
{
istZahl = true;
}
else
{
istZahl = false;
}
return istZahl;
}
private static Boolean textfeldRot(String pBreiteBitmap, String pHoeheBitmap, String pAnzahlKoordinaten)
{
Boolean istRot = true;
if (pBreiteBitmap.Equals("61381638") || pHoeheBitmap.Equals("61381638") || pAnzahlKoordinaten.Equals("61381638"))
{
istRot = true;
}
else
{
istRot = false;
}
return istRot;
}
private void btSpeichern_Click(object sender, RoutedEventArgs e)
{
if (textfeldRot(tbBreiteBitmap.BorderBrush.GetHashCode().ToString(), tbHoeheBitmap.BorderBrush.GetHashCode().ToString(), tbAnzahlKoordinaten.BorderBrush.GetHashCode().ToString()))
{
MessageBox.Show("Leider beinhalten die Eingabefelder falsche Werte.\n\nVersuchen Sie es bitte erneut.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
try
{
Vorschau.Properties.Settings.Default.BreiteBitmap = Int32.Parse(tbBreiteBitmap.Text);
Vorschau.Properties.Settings.Default.HoeheBitmap = Int32.Parse(tbHoeheBitmap.Text);
Vorschau.Properties.Settings.Default.AnzahlKoordinaten = Int32.Parse(tbAnzahlKoordinaten.Text);
MessageBox.Show("Einstellungen wurden erfolgreich abgespeichert.", "Speicherung erfolgreich", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
catch (Exception error)
{
MessageBox.Show("Unglücklicherweise trat beim Speichervorgang ein Fehler auf.\n\nVersuchen Sie es bitte erneut.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
Debug.WriteLine("Error - beim Speichervorgang " + error);
}
}
}
private void tbBreiteBitmap_LostFocus(object sender, RoutedEventArgs e)
{
try
{
if (kontrolliereObZahl(tbBreiteBitmap.Text) == false)
{
tbBreiteBitmap.BorderBrush = Brushes.Red;
}
else
{
tbBreiteBitmap.BorderBrush = Brushes.LightGray;
}
}
catch (Exception error)
{
Debug.WriteLine("Error 'tbBreitBitMap'" + error);
}
}
private void tbHoeheBitmap_LostFocus(object sender, RoutedEventArgs e)
{
try
{
if (kontrolliereObZahl(tbHoeheBitmap.Text) == false)
{
tbHoeheBitmap.BorderBrush = Brushes.Red;
}
else
{
tbHoeheBitmap.BorderBrush = Brushes.LightGray;
}
}
catch (Exception error)
{
Debug.WriteLine("Error 'tbHoeheBitmap'" + error);
}
}
private void tbAnzahlKoordinaten_LostFocus(object sender, RoutedEventArgs e)
{
try
{
if (kontrolliereObZahl(tbAnzahlKoordinaten.Text) == false)
{
tbAnzahlKoordinaten.BorderBrush = Brushes.Red;
}
else
{
tbAnzahlKoordinaten.BorderBrush = Brushes.LightGray;
}
}
catch (Exception error)
{
Debug.WriteLine("Error 'tbAnzahlKoordinaten'" + error);
}
}
}
}
<UserControl x:Class="Vorschau.UCEinstellung"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Vorschau"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="0,0,-326,-161">
<TextBox x:Name="tbBreiteBitmap" HorizontalAlignment="Left" Height="23" Margin="145,38,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="85" LostFocus="tbBreiteBitmap_LostFocus"/>
<TextBox x:Name="tbHoeheBitmap" HorizontalAlignment="Left" Height="23" Margin="145,83,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="85" LostFocus="tbHoeheBitmap_LostFocus"/>
<Label x:Name="label" Content="Breite:" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top"/>
<Label x:Name="label_Copy" Content="Höhe:" HorizontalAlignment="Left" Margin="10,77,0,0" VerticalAlignment="Top"/>
<Label x:Name="label_Copy1" Content="in PX" HorizontalAlignment="Left" Margin="247,35,0,0" VerticalAlignment="Top"/>
<Label x:Name="label_Copy2" Content="in PX" HorizontalAlignment="Left" Margin="247,77,0,0" VerticalAlignment="Top"/>
<Label x:Name="label1" Content="einstellbare Größe des Bitmaps" HorizontalAlignment="Left" Margin="10,5,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<Label x:Name="label1_Copy" Content="einstellbare Zahl der geenerierten Koordinaten" HorizontalAlignment="Left" Margin="10,172,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<Label x:Name="label_Copy3" Content="Anzahl Koordinaten:" HorizontalAlignment="Left" Margin="10,203,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="tbAnzahlKoordinaten" HorizontalAlignment="Left" Height="23" Margin="145,203,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="85" LostFocus="tbAnzahlKoordinaten_LostFocus"/>
<Image x:Name="image" HorizontalAlignment="Left" Height="350" Margin="289,10,0,0" VerticalAlignment="Top" Width="350" Source="img/imageedit_1_9734874017.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Label x:Name="label1_Copy1" Content="Wertebreich des Koordinatensystems" HorizontalAlignment="Left" Margin="323,5,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<Canvas HorizontalAlignment="Left" Height="405" Margin="299,23,0,0" VerticalAlignment="Top" Width="3" Background="#FFB8B8B8" RenderTransformOrigin="0.5,0.5">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="-1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<Button x:Name="btSpeichern" Content="Speichern" HorizontalAlignment="Left" Margin="30,418,0,0" VerticalAlignment="Top" Width="75" Click="btSpeichern_Click"/>
</Grid>
</UserControl>
MainWindow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Vorschau
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
UCEinstellung einstellung = new UCEinstellung();
UCVorschau vorschau = new UCVorschau();
public MainWindow()
{
InitializeComponent();
MouseDown += Window_MouseDown;
einstellung.tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
einstellung.tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
einstellung.tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
private void lbClose_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
this.Close();
}
private void lbMinimize_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
lbWhereIAm.Content = "Vorschau";
conCon.Content = vorschau;
}
private void btEinstellung_Click(object sender, RoutedEventArgs e)
{
lbWhereIAm.Content = "Einstellung";
einstellung.tbBreiteBitmap.Text = "Test";
conCon.Content = einstellung;
einstellung.tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
einstellung.tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
einstellung.tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Vorschau
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
UCEinstellung einstellung = new UCEinstellung();
UCVorschau vorschau = new UCVorschau();
public MainWindow()
{
InitializeComponent();
MouseDown += Window_MouseDown;
einstellung.tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
einstellung.tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
einstellung.tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
private void lbClose_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
this.Close();
}
private void lbMinimize_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
lbWhereIAm.Content = "Vorschau";
conCon.Content = vorschau;
}
private void btEinstellung_Click(object sender, RoutedEventArgs e)
{
lbWhereIAm.Content = "Einstellung";
einstellung.tbBreiteBitmap.Text = "Test";
conCon.Content = einstellung;
einstellung.tbBreiteBitmap.Text = Vorschau.Properties.Settings.Default.BreiteBitmap.ToString();
einstellung.tbHoeheBitmap.Text = Vorschau.Properties.Settings.Default.HoeheBitmap.ToString();
einstellung.tbAnzahlKoordinaten.Text = Vorschau.Properties.Settings.Default.AnzahlKoordinaten.ToString();
}
}
}
<Window x:Name="windowsForm" x:Class="Vorschau.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:Vorschau"
mc:Ignorable="d"
Title="Vorschaukomponente" Height="514.583" Width="805.208" FontFamily="Century Gothic" WindowStartupLocation="Manual" BorderThickness="0" ResizeMode="NoResize" WindowStyle="None" Icon="img/coordinates.ico" Background="{x:Null}" AllowsTransparency="True">
<Window.Resources>
<Style x:Key="border_res" TargetType="{x:Type Border}">
<Setter Property="Background" Value="#3A3A3B" />
<Setter Property="CornerRadius" Value="10" />
</Style>
</Window.Resources>
<Border Style="{StaticResource border_res}">
<Grid>
<Canvas HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="185" Background="#FFE57E31">
<Canvas Height="64" Canvas.Top="451" Width="185" Background="#FF2C373F">
<Label x:Name="lbCopyright" Content="© Name 2017" Canvas.Left="10" Canvas.Top="29" Width="121" Foreground="#FF1B1D1F"/>
</Canvas>
<Canvas Height="391" Canvas.Top="60" Width="185" Background="#FF37424A">
<Button x:Name="btVorschau" Content="Vorschau" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" Foreground="LightGray" FontSize="16"
HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Click="Button_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button x:Name="btEinstellung" Content="Einstellung" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" Foreground="LightGray" FontSize="16"
HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Canvas.Top="50" Click="btEinstellung_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Canvas>
<Canvas Height="60" Canvas.Left="185" Width="618" Background="#FFEEE9ED">
<Label x:Name="lbClose" Content="X" Canvas.Left="578" FontSize="20" MouseDoubleClick="lbClose_MouseDoubleClick"/>
<Label x:Name="lbMinimize" Content="-" Canvas.Left="556" FontSize="22" Canvas.Top="-2" MouseDoubleClick="lbMinimize_MouseDoubleClick"/>
<Label x:Name="lbWhereIAm" Content="Label" Canvas.Left="10" Canvas.Top="15" Width="162" FontSize="20"/>
</Canvas>
<Canvas x:Name="canvasContent" Height="455" Canvas.Left="185" Canvas.Top="60" Width="618" Background="#FFD1CFD0"/>
<Image x:Name="image" Height="38" Canvas.Left="10" Canvas.Top="10" Width="38" Source="img/coordinatesWhite.png"/>
<Label x:Name="lbLogoname" Content="Vorschaukomponente" Canvas.Left="37" Canvas.Top="10" Width="143" FontWeight="Bold" Foreground="White"/>
</Canvas>
<ContentControl x:Name="conCon" Content="ContentControl" Canvas.Left="86" Canvas.Top="31" Margin="185,60,0,0" Foreground="#FF002EFF"/>
</Grid>
</Border>
</Window>
It looks like you are just assigning the properties and not saving them. You need to call the Save method
Vorschau.Properties.Settings.Default.Save();
You can find the file under %userprofile%\appdata\local after saving. See here for details.
For this to work, the scope of the setting should be "User".
Related
What I'm trying to do is I have a textbox, and a '-' and a '+' button, and on button click I need to decrease/increase it's value. I have close to 0 experience with WPF, we only learnt console apps in school and now we got this task and I have no idea why this code sample is not working:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace sudokuGUI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
int ertek = Convert.ToInt32(textBox1.Text);
if (ertek > 4)
{
textBox1.Text = $"{ertek--}";
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int ertek = Convert.ToInt32(textBox1.Text);
if (ertek < 9)
{
textBox1.Text = $"{ertek++}";
}
}
}
}
<Window x:Class="sudokuGUI.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:sudokuGUI"
mc:Ignorable="d"
Title="Sudoku-ellenőrző" Height="210" Width="540">
<Grid>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="512" Margin="10,90,0,0"/>
<Label Content="Új feladvány mérete:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<Button Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Width="20" Margin="144,13,0,0" Click="Button_Click"/>
<Button Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Width="20" Margin="194,13,0,0" Click="Button_Click_1"/>
<Label Content="Kezdőállapot:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,59,0,0"/>
<Label x:Name="label1" Content="Hossz: 0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,118,0,0"/>
<Button Content="Ellenőrzés" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="447,118,0,0"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="20" TextWrapping="Wrap" Text="4" VerticalAlignment="Top" Width="20" Margin="169,13,0,0" TextAlignment="Center" IsEnabled="False"/>
</Grid>
</Window>
Any help is appreciated!
ertek++ is a postfix increment operator. The result of ertek++ is the value of ertek before the operation.
use simple + operator:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int ertek = Convert.ToInt32(textBox1.Text);
if (ertek < 9)
{
textBox1.Text = $"{ertek+1}";
}
}
I'm trying to bind a variable to show in a label's content.
I use Galasoft's MVVM light to achieve this.
I send my viewmodel, my window and my window.cs. The issue is that nothing happens when I increase the values but something should.
Window: I have binding on only one label
<Window x:Class="DPCKOU_prog3hf_pong.Settings"
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:DPCKOU_prog3hf_pong"
mc:Ignorable="d"
Title="Settings" Height="406" Width="717"
Background="{StaticResource MainMenuBG}"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
>
<Grid>
<StackPanel>
<Label x:Name="Title" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch"
Foreground="#00e4ff" FontSize ="28" Content="Size of pad"
Margin="10,30,10,10">
<Label.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Label.BitmapEffect>
</Label>
<Label x:Name="Size" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch"
Foreground="#00e4ff" FontSize ="40" Content="{Binding Path=PadSize}"
Margin="10,0,10,10">
<Label.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Label.BitmapEffect>
</Label>
<DockPanel>
<Button x:Name="Increase" Content="Increase" HorizontalAlignment="Left"
Width="149" Height="46" Foreground="#00e4ff" Background="Black" Margin="120,10,10,10"
FontSize="18" BorderThickness="0" Click="Increase_Click">
<Button.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Button.BitmapEffect>
</Button>
<Button x:Name="Decrease" Content="Decrease" HorizontalAlignment="Right"
Width="149" Height="46" Foreground="#00e4ff" Background="Black" Margin="10,10,120,10"
FontSize="18" BorderThickness="0" Click="Decrease_Click">
<Button.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Button.BitmapEffect>
</Button>
</DockPanel>
<Button x:Name="Play" Content="Play" HorizontalAlignment="Center"
Width="149" Height="46" Foreground="#00e4ff" Background="Black" Margin="10,10,10,10"
FontSize="18" BorderThickness="0" Click="Play_Click">
<Button.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Button.BitmapEffect>
</Button>
<Button x:Name="Back" Content="Back" HorizontalAlignment="Center"
Width="149" Height="46" Foreground="#00e4ff" Background="Black" Margin="10,10,10,10"
FontSize="18" BorderThickness="0" Click="Back_Click">
<Button.BitmapEffect>
<DropShadowBitmapEffect Color="#00e4ff" ShadowDepth="0" Opacity="1"/>
</Button.BitmapEffect>
</Button>
</StackPanel>
</Grid>
The model's cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
namespace DPCKOU_prog3hf_pong
{
class SettingsVM : ViewModelBase
{
int padSize;
public int PadSize
{
get
{
return padSize;
}
set
{
if(value >=1 && value <= 6)
{
Set(ref padSize, value);
}
}
}
public SettingsVM()
{
padSize = 1;
}
}
}
and the window.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;
namespace DPCKOU_prog3hf_pong
{
/// <summary>
/// Interaction logic for SingleSettings.xaml
/// </summary>
///
/*
* take it 100 pixels is the 4 units of the pad's size respectively.
* so 25 shall be 1 and that is the default value one can input.
* the player can input pad size from 1 to 6 meaning from 25 pixels to 150.
*/
public partial class Settings : Window
{
/*
* its sole purpose is to change the pad size.
*/
SettingsVM svm;
bool isPlaymodeSingle;
public Settings(bool isPlaymodeSingle)
{
InitializeComponent();
this.isPlaymodeSingle = isPlaymodeSingle;
svm = new SettingsVM();
}
private void Play_Click(object sender, RoutedEventArgs e)
{
if (isPlaymodeSingle)
{
//yes, solo
SinglePlayer spgame = new SinglePlayer();
spgame.Show();
Close();
/*
* show the game window and close this.
*/
}
else
{
//nope, multi.
}
}
private void Decrease_Click(object sender, RoutedEventArgs e)
{
svm.PadSize--;
}
private void Increase_Click(object sender, RoutedEventArgs e)
{
svm.PadSize++;
}
private void Back_Click(object sender, RoutedEventArgs e)
{
MainWindow mw = new MainWindow();
mw.Show();
Close();
}
}
}
You forgot to set the DataContext of the Window.
You can do that for example in the constructor of the Settings class:
public Settings(bool isPlaymodeSingle)
{
InitializeComponent();
this.isPlaymodeSingle = isPlaymodeSingle;
svm = new SettingsVM();
DataContext = svm; // here
}
I'm trying to get my app bar to appear when I tap the 3 dots at the bottom of the screen, but when I do so it doesn't happen. Anyone know why & how this problem can be rectified?
MainPage.xaml
<Page
x:Name="pageRoot"
x:Class="HP.MainPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Exits_Expert_London_Lite.Lines_and_Stations.WC"
xmlns:common="using:Exits_Expert_London_Lite.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:q42controls="using:Q42.WinRT.Controls"
mc:Ignorable="d">
<Grid Background="Black">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid Name="CustomAppBarRoot" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Loaded="CustomAppBarRoot_OnLoaded"
ManipulationMode="TranslateY"
ManipulationDelta="CustomAppBarRoot_OnManipulationDelta"
ManipulationCompleted="CustomAppBarRoot_OnManipulationCompleted"
Tapped="CustomAppBarRoot_OnTapped">
<Grid.RenderTransform>
<TranslateTransform X="0" Y="0"/>
</Grid.RenderTransform>
<Grid.Background>
<SolidColorBrush Color="Black" Opacity="0.5"></SolidColorBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Name="DotsTextBlock" FontSize="28" Text="..." HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="0 0 15 0" Tapped="DotsTextBlock_OnTapped" Width="50" Height="50" TextAlignment="Center">
<TextBlock.RenderTransform>
<TranslateTransform Y="0" X="11"/>
</TextBlock.RenderTransform>
</TextBlock>
<StackPanel Name="ButtonsStackPanel" Grid.Row="1" Orientation="Horizontal">
<AppBarButton Label="tfg" Icon="Add"/>
<AppBarButton Label="tfg" Icon="Add"/>
</StackPanel>
</Grid>
<Hub>
<Hub.Header>
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Margin="-1,-1,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock x:Name="pageTitle" Text="Page name" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Top"/>
</Grid>
</Hub.Header>
<HubSection Width="800" Padding="40,50,0,0">
<HubSection.Header>
<StackPanel>
<TextBlock Text="hub section 1" Style="{StaticResource HeaderTextBlockStyle}"/>
</StackPanel>
</HubSection.Header>
<DataTemplate>
<Grid>
<StackPanel>
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Margin="0,0,0,5" TextWrapping="Wrap">
<Run Text="Hello World"/>
</TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</HubSection>
</Hub>
</Grid>
</Page>
MainPage.cs
using HP.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;
// The Hub Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=321224
namespace HP
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Tapped += Page_OnTapped;
}
private void Page_OnTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs)
{
if ( isAppBarShown )
HideCustomAppBar();
}
#region custom app bar
private Storyboard hideCustomAppBarStoryboard;
private Storyboard showCustomAppBarStoryboard;
private Size appBarSize;
private Size appBarButtonsSize;
private bool isAppBarShown = true;
private void CustomAppBarRoot_OnLoaded(object sender, RoutedEventArgs e)
{
appBarSize = new Size(CustomAppBarRoot.ActualWidth, CustomAppBarRoot.ActualHeight);
appBarButtonsSize = new Size(ButtonsStackPanel.ActualWidth, ButtonsStackPanel.ActualHeight);
InitializeStoryboards();
HideCustomAppBar();
}
private void ShowCustomAppBar()
{
isAppBarShown = true;
showCustomAppBarStoryboard.Begin();
}
private void HideCustomAppBar()
{
isAppBarShown = false;
hideCustomAppBarStoryboard.Begin();
}
private void DotsTextBlock_OnTapped(object sender, TappedRoutedEventArgs e)
{
if (isAppBarShown)
HideCustomAppBar();
else
ShowCustomAppBar();
}
private void InitializeStoryboards()
{
hideCustomAppBarStoryboard = new Storyboard();
showCustomAppBarStoryboard = new Storyboard();
var showDoubleAnimation = new DoubleAnimation()
{
EasingFunction = new CircleEase() {EasingMode = EasingMode.EaseInOut},
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(200))
};
var hideDoubleAnimation = new DoubleAnimation()
{
EasingFunction = new CubicEase() {EasingMode = EasingMode.EaseInOut},
To = appBarButtonsSize.Height,
Duration = new Duration(TimeSpan.FromMilliseconds(200))
};
hideCustomAppBarStoryboard.Children.Add(hideDoubleAnimation);
showCustomAppBarStoryboard.Children.Add(showDoubleAnimation);
Storyboard.SetTarget(hideCustomAppBarStoryboard, CustomAppBarRoot);
Storyboard.SetTarget(showCustomAppBarStoryboard, CustomAppBarRoot);
Storyboard.SetTargetProperty(showCustomAppBarStoryboard, "(UIElement.RenderTransform).(TranslateTransform.Y)");
Storyboard.SetTargetProperty(hideCustomAppBarStoryboard, "(UIElement.RenderTransform).(TranslateTransform.Y)");
}
#endregion
private void CustomAppBarRoot_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var translateTransform = (CustomAppBarRoot.RenderTransform as TranslateTransform);
double newY = e.Delta.Translation.Y + translateTransform.Y;
translateTransform.Y = Math.Max(0, Math.Min(newY, appBarButtonsSize.Height));
}
private void CustomAppBarRoot_OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
// if small appbar-position changes are made app bar should back to previous position, just like in windows phone
if (Math.Abs(e.Cumulative.Translation.Y) < 20)
isAppBarShown = !isAppBarShown;
if (!isAppBarShown)
ShowCustomAppBar();
else
HideCustomAppBar();
}
private void CustomAppBarRoot_OnTapped(object sender, TappedRoutedEventArgs e)
{
e.Handled = true; // prevents raising Page.Tapped event so appbar won't be closed on AppBar-area tap
}
}
}
Move your CustomAppBarRoot Grid after the Hub control so it renders on top. As is, the Hub control covers the CustomAppBarRoot so clicks on the ellipses go to the Hub not to the DotsTextBlock. If you give the Hub a background colour for testing this is quite obvious (leave the Background off for production):
<Hub Background="Magenta">
You could also raise the CustomAppBarRoot in the Z-order by applying the Canvas.ZIndex property; however, since your CustomAppBarRoot isn't in a Canvas this is an off-label use so I'd prefer placing the CustomAppBarRoot after the Hub in the Xaml:
<Grid Name="CustomAppBarRoot" Canvas.ZIndex="100" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Loaded="CustomAppBarRoot_OnLoaded"
There is a Segoe UI Symbol for the "More" ellipses at Unicode 0xe10c that you might use rather than using a string of periods:
<TextBlock Name="DotsTextBlock" Text="" FontSize="14" FontFamily="Segoe UI Symbol" HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="0 0 15 0" Tapped="DotsTextBlock_OnTapped" Width="50" Height="50" TextAlignment="Center">
<TextBlock.RenderTransform>
<TranslateTransform Y="0" X="11"/>
</TextBlock.RenderTransform>
</TextBlock>
i have two user control and when i click on a button from the first user control ,another user control shows up :
The first user control is:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Navigateur.Presentation.UserControlWork
{
/// <summary>
/// Logique d'interaction pour ListeBlanche.xaml
/// </summary>
public partial class ListeBlanche : UserControl
{
public ListeBlanche()
{
InitializeComponent();
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
ServiceReferenceParent.ParentServiceClient wcfParent = new ServiceReferenceParent.ParentServiceClient();
bool existe = await wcfParent.LogInAsync(textmail.Text, textpass.Text);
if (existe)
{
//grid.Children.Remove(this);
//this.Visibility = System.Windows.Visibility.Collapsed;
//ParentControl parmain = new ParentControl();
//parmain.Visibility = System.Windows.Visibility.Visible;
//parmain.
}
else
{
Popup1.IsOpen = true;
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
MainWindow main = new MainWindow();
ParentControl parmain = new ParentControl();
main.gridMain.Children.Add(parmain);
parmain.Visibility = System.Windows.Visibility.Visible;
this.Visibility = System.Windows.Visibility.Hidden;
}
}
}
and when i click on "Button_Click_2",ParentControl shows up but it never shows.
Fullscreen:
this is the ParenControl xaml code:
`<UserControl x:Class="Navigateur.Presentation.UserControlWork.ParentControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Width="586.194" Height="316.418">
<Grid Background="#FF65B4EC" ClipToBounds="True">
<Canvas HorizontalAlignment="Left" Height="69" VerticalAlignment="Top" Width="586" Background="#FF5ACAFF" ClipToBounds="True">
<Label Content="Création de votre compte parent" Canvas.Left="188" Canvas.Top="20" RenderTransformOrigin="0.5,0.5" Width="155" Background="#FF65B4EC" FontWeight="Black">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-0.376"/>
<TranslateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
</Canvas>
<Label Content="Nom Compte" HorizontalAlignment="Left" Margin="121,106,0,0" VerticalAlignment="Top"/>
<Label Content="Pseudo" HorizontalAlignment="Left" Margin="323,165,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.498,0.006"/>
<Label Content="Prénom" HorizontalAlignment="Left" Margin="121,219,0,0" VerticalAlignment="Top"/>
<Label Content="Nom" HorizontalAlignment="Left" Margin="323,214,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.2,0.471"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="121,132,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="335"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="323,191,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="133"/>
<RadioButton Content="Monsieur" HorizontalAlignment="Left" Margin="121,191,0,0" VerticalAlignment="Top" Height="23"/>
<RadioButton Content="Madame" HorizontalAlignment="Left" Margin="192,191,0,0" VerticalAlignment="Top" Height="23"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="121,245,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="131"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="323,245,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="133" RenderTransformOrigin="0.5,0.5"/>
<Button Content="Annuler" HorizontalAlignment="Left" Margin="192,288,0,0" VerticalAlignment="Top" Width="75" Height="23"/>
<Button Content="Suivant" HorizontalAlignment="Left" Margin="297,288,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</UserControl>`
and this is my main window xaml code:
<Window x:Name="wndmain" x:Class="Navigateur.Presentation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:auth="clr-namespace:Navigateur.Presentation.UserControlWork"
Title="MainWindow" Height="317" Width="586.194" WindowState="Maximized" WindowStyle="None" Topmost="True" ResizeMode="NoResize">
<Grid x:Name="gridMain">
<auth:ListeBlanche ClickedInUserControl="OnClickedInUserControl"></auth:ListeBlanche>
</Grid>
</Window>
I think you need to use a RoutedEvent in your UserControl to get this to work.
So change your click event in your usercontrol to:
public event RoutedEventHandler ClickedInUserControl;
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if (ClickedInUserControl != null)
{
ClickedInUserControl(this, new RoutedEventArgs());
}
}
Then in you MainWindow's xaml add this too the UserControl:
ClickedInUserControl="OnClickedInUserControl"
And then add the event handler on your mainwindow's codebehind
private void OnClickedInUserControl(object sender, RoutedEventArgs e)
{
ParentControl parmain = new ParentControl();
this.gridMain.Children.Add(parmain);
parmain.Visibility = System.Windows.Visibility.Visible;
// also remove the original usercontrol from the grid and collapse it's vilisibilty
}
Also, I would highly recommend that you look into using Commands rather than Events for this kind of thing, but I used events because that's what you were working with.
I have a slider with minimum 0 and max 100.
I have a popup window that is visible when I mouseover the slider.
Currently, I binded the popup with the slider value.
What I want is:
When I move the mouse over the slider, I want to see value that suppose to be in that position.
For example:
My XAML:
<Window x:Class="WPFMavka.VideoPlayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFMavka"
Title="MainWindow" WindowStyle="None" Width="1920" Height="1080" WindowState="Maximized" KeyboardNavigation.TabNavigation="None" Closing="Window_Closing">
<Grid Name="tst">
<local:MetroSlider x:Name="bla" MouseMove="Rectangle_MouseMove" MouseLeave="Rectangle_MouseLeave" IsMoveToPointEnabled="True" HorizontalAlignment="Left" Width="542" VerticalAlignment="Top" Margin="116,839,0,0" Value="0" Style="{DynamicResource SliderStyle1}" Height="66" AutoToolTipPrecision="0" AutoToolTipPlacement="TopLeft"/>
<Popup Name="floatingTip" AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=bla}">
<Border BorderBrush="Black" BorderThickness="1" Padding="4">
<TextBlock Text="{Binding ElementName=bla, Path=Value}"></TextBlock>
</Border>
</Popup>
</Grid>
</Window>
My Code-Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WPFMavka
{
/// <summary>
/// Interaction logic for VideoPlayer.xaml
/// </summary>
public partial class VideoPlayer : Window
{
public VideoPlayer()
{
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Environment.Exit(1);
}
private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
if (!floatingTip.IsOpen) { floatingTip.IsOpen = true; }
Point currentPos = e.GetPosition(bla);
floatingTip.HorizontalOffset = currentPos.X-14;
floatingTip.VerticalOffset = -32;
}
private void Rectangle_MouseLeave(object sender, MouseEventArgs e)
{
floatingTip.IsOpen = false;
}
}
}
Found a better solution - changing the TextBlock onMouseOver the slide > I get the current position of mouse on the slider and then uses .ValueFromPoint()
XAML:
<Window x:Class="WPFMavka.VideoPlayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFMavka"
Title="MainWindow" WindowStyle="None" Width="1920" Height="1080" WindowState="Maximized" KeyboardNavigation.TabNavigation="None" Closing="Window_Closing">
<Grid Name="tst">
<local:MetroSlider x:Name="slider" MouseMove="slider_MouseMove" MouseLeave="slider_MouseLeave" IsMoveToPointEnabled="True" HorizontalAlignment="Left" Width="746" VerticalAlignment="Top" Margin="330,851,0,0" Value="0" Style="{DynamicResource SliderStyle1}" Height="44"/>
<Popup Name="floatingTip" AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=slider}">
<Border Name="floatingTipBorder" BorderBrush="Black" BorderThickness="1" Padding="4">
<TextBlock Name="sliderTextBlock"/>
</Border>
</Popup>
</Grid>
</Window>
Code-Behind:
private void slider_MouseMove(object sender, MouseEventArgs e)
{
if (!floatingTip.IsOpen) { floatingTip.IsOpen = true; }
Point currentPos = e.GetPosition(slider);
Track _track = slider.Template.FindName("PART_Track", slider) as Track;
sliderTextBlock.Text = _track.ValueFromPoint(currentPos).ToString();
floatingTip.HorizontalOffset = currentPos.X -(floatingTipBorder.ActualWidth / 2);
floatingTip.VerticalOffset = -32;
}
private void slider_MouseLeave(object sender, MouseEventArgs e)
{
floatingTip.IsOpen = false;
}
You can use AttachedCommands for this. You can download the library from here. So in this case you could do something like:
<Window x:Class="WPFMavka.VideoPlayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFMavka"
xmlns:AttachedCommand="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
Title="MainWindow"
WindowStyle="None"
Width="1920"
Height="1080"
WindowState="Maximized"
KeyboardNavigation.TabNavigation="None"
Closing="Window_Closing">
<Grid Name="tst">
<local:MetroSlider x:Name="bla"
MouseMove="Rectangle_MouseMove"
MouseLeave="Rectangle_MouseLeave"
IsMoveToPointEnabled="True"
HorizontalAlignment="Left"
Width="542" VerticalAlignment="Top"
Margin="116,839,0,0"
Value="0"
Style="{DynamicResource SliderStyle1}"
Height="66" AutoToolTipPrecision="0"
AutoToolTipPlacement="TopLeft"
AttachedCommand:CommandBehavior.Event="MouseMove"
AttachedCommand:CommandBehavior.Command="{Binding UpdateCurrentMouseTimeCommand}"
AttachedCommand:CommandBehavior.CommandParameter="{Binding ElementName=Bla, Path=Value}"/>
<Popup Name="floatingTip" AllowsTransparency="True"
Placement="Relative"
PlacementTarget="{Binding ElementName=bla}">
<Border BorderBrush="Black" BorderThickness="1" Padding="4">
<TextBlock Text="{Binding CurrentMouseTime, NotifyOnSourceUpdated=True, Mode=OneWay}" />
</Border>
</Popup>
</Grid>
</Window>
Then in your command UpdateCurrentMouseTimeCommand you set the property
private string currentMouseTime = String.Empty;
public string CurrentMouseTime
{
get { return value; }
set
{
if (currentMouseTime == value)
return;
currentMouseTime = value;
OnPropertyChanged("CurrentMouseTime");
}
}
Where the containing class must implement INotifyPropertyChanged.
I hope this helps.