dimanche 28 décembre 2014

WPF Short binding


Vote count:

-1




I really dont understand why i cant binding like it:



<Label Content="{Binding SomeObiect}"/>


In very often see something like it but in my programs dont work... Why? :(



<UserControl x:Class="GAME___ala_Mario.View.Controls.SkillButton"
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:Converers="clr-namespace:GAME___ala_Mario.View.Converters"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Name="btn_Skill">



<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>

<!--Tło-->
<Viewbox Grid.Column="0" Grid.Row="0"
Grid.ColumnSpan="2" Grid.RowSpan="2">
<!-- AND I USE BINDING LIKE IT: (always) -->
<Image Source="{Binding ElementName=btn_Skill, Path=BackgroundImageSource}"/>
</Viewbox>



</Grid>
</UserControl>


And 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.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 GAME___ala_Mario.View.Controls
{
/// <summary>
/// Interaction logic for SkillButton.xaml
/// </summary>
public partial class SkillButton : UserControl
{
public static readonly DependencyProperty KeyPressProperty = DependencyProperty.Register("KeyPress", typeof(char), typeof(SkillButton));
public static readonly DependencyProperty BackgroundImageSourceProperty = DependencyProperty.Register("BackgroundImageSource", typeof(ImageSource), typeof(SkillButton));
public static readonly DependencyProperty BackgroundDefaultColorProperty = DependencyProperty.Register("BackgroundDefaultColor", typeof(Color), typeof(SkillButton), new FrameworkPropertyMetadata(Colors.Transparent));
public static readonly DependencyProperty BackgroundHowerColorProperty = DependencyProperty.Register("BackgroundHowerColor", typeof(Color), typeof(SkillButton), new FrameworkPropertyMetadata(Colors.SteelBlue));
public static readonly DependencyProperty SkillImageSourceProperty = DependencyProperty.Register("SkillImageSource", typeof(ImageSource), typeof(SkillButton));
public static readonly DependencyProperty BorderDefaultColorProperty = DependencyProperty.Register("BorderDefaultColor", typeof(Color), typeof(SkillButton), new FrameworkPropertyMetadata(Colors.Black));
public static readonly DependencyProperty BorderHowerColorProperty = DependencyProperty.Register("BorderHowerColor", typeof(Color), typeof(SkillButton), new FrameworkPropertyMetadata(Colors.BlueViolet));
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register("Size", typeof(Int32), typeof(SkillButton), new FrameworkPropertyMetadata((Int32)100));


/// <summary>
/// Przycisk który będzie wywoływał akcje
/// oraz jaki znak będzie wyświetlany na przycisku
/// </summary>
public char KeyPress
{
get { return (char)GetValue(KeyPressProperty); }
set { SetValue(KeyPressProperty, value); }
}


/// <summary>
/// Link do obrazka który będzie w tle
/// </summary>
public ImageSource BackgroundImageSource
{
get { return (ImageSource)GetValue(BackgroundImageSourceProperty); }
set { SetValue(BackgroundImageSourceProperty, value); }
}


/// <summary>
/// Link do obrazka który będzie wyświetlany na środku przycisku
/// </summary>
public ImageSource SkillImageSource
{
get { return (ImageSource)GetValue(SkillImageSourceProperty); }
set { SetValue(SkillImageSourceProperty, value); }
}


/// <summary>
/// Definiuje jakiego koloru ma być tło
/// </summary>
public Color BackgroundDefaultColor
{
get { return (Color)GetValue(BackgroundDefaultColorProperty); }
set { SetValue(BackgroundDefaultColorProperty, value); }
}



/// <summary>
/// Definiuje jakiego koloru ma być tło obiektu w chwili najechania myszką
/// </summary>
public Color BackgroundHowerColor
{
get { return (Color)GetValue(BackgroundHowerColorProperty); }
set { SetValue(BackgroundHowerColorProperty, value); }
}


/// <summary>
/// Definiuje jakiego koloru ma być obramowanie
/// </summary>
public Color BorderDefaultColor
{
get { return (Color)GetValue(BorderDefaultColorProperty); }
set { SetValue(BorderDefaultColorProperty, value); }
}


/// <summary>
/// Definiuje jakiego koloru ma być obramowanie w chwili najechania myszką
/// </summary>
public Color BorderHowerColor
{
get { return (Color)GetValue(BorderHowerColorProperty); }
set { SetValue(BorderHowerColorProperty, value); }
}


/// <summary>
/// Definije rozmiar bloku
/// </summary>
public Int32 Size
{
get { return (Int32)GetValue(SizeProperty); }
set { SetValue(SizeProperty, value); }
}

public SkillButton()
{
InitializeComponent();
}
}
}


DONT READ ~ BOT WANT MORE DETAILS DONT READ ~ BOT WANT MORE DETAILS DONT READ ~ BOT WANT MORE DETAILS DONT READ ~ BOT WANT MORE DETAILS DONT READ ~ BOT WANT MORE DETAILS DONT READ ~ BOT WANT MORE DETAILS



asked 1 min ago







WPF Short binding

Aucun commentaire:

Enregistrer un commentaire