'컨트롤'에 해당되는 글 3건

  1. 2018.11.13 라디오 컨트롤 바인딩
  2. 2017.08.08 MVVM 하위 컨트롤 바인딩
  3. 2012.03.22 [wp7] 별점 컨트롤 (Rating Control)
wpf2018. 11. 13. 16:20


namespace WpfRadioButton
{
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Markup;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ViewModel vm = new ViewModel();
        public MainWindow()
        {
            InitializeComponent();

            DataContext = vm;
        }
    }

    [ValueConversion(typeof(bool), typeof(Enum))]
    public class EnumToBoolExtension : MarkupExtensionIValueConverter
    {
        #region IValueConverter
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return parameter.Equals(value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((bool) value) == true ? parameter : DependencyProperty.UnsetValue;
        }

        #endregion

        #region MarkupExtension

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        #endregion
    }

    public enum Direction
    {
           North,
        Easth,
        West,
        South
    }

    public class ViewModel : INotifyPropertyChanged
    {
        public Direction direction;

        public Direction Direction
        {
            get
            {
                return this.direction;
            }

            set
            {
                this.direction = value;
                this.RaisePropertyChanged("Direction");
            }
        }

        #region NotifyPropertyChanged Methods

        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;

            if (handler != null)
            {
                handler(thisnew PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}


<Window x:Class="WpfRadioButton.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:local="clr-namespace:WpfRadioButton"
        Title="RadioButton" Height="200" Width="300">
    <Grid DataContext="{Binding}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <RadioButton Grid.Row="0" GroupName="directionText" Margin="5" VerticalAlignment="Center" Content="North" 
                     IsChecked="{Binding Direction, Converter={local:EnumToBool}, ConverterParameter={x:Static local:Direction.North}}"/>
        <RadioButton Grid.Row="1" GroupName="directionText" Margin="5" VerticalAlignment="Center" Content="East" 
                     IsChecked="{Binding Direction, Converter={local:EnumToBool}, ConverterParameter={x:Static local:Direction.Easth}}"/>
        <RadioButton Grid.Row="2" GroupName="directionText" Margin="5" VerticalAlignment="Center" Content="West" 
                     IsChecked="{Binding Direction, Converter={local:EnumToBool}, ConverterParameter={x:Static local:Direction.West}}"/>
        <RadioButton Grid.Row="3" GroupName="directionText" Margin="5" VerticalAlignment="Center" Content="South" 
                     IsChecked="{Binding Direction, Converter={local:EnumToBool}, ConverterParameter={x:Static local:Direction.South}}"/>
        <TextBlock Grid.Row="4" Margin="5" VerticalAlignment="Center" Text="{Binding Direction}"/>
    </Grid>
</Window>

출처 : https://zamjad.wordpress.com/2014/03/01/radio-button-in-mvvm/

Posted by 동동(이재동)
wpf2017. 8. 8. 16:18

예를들어 View의 UserControl의 DataContext에 데이터를 주입하고

 <local:CardCancelControl DataContext="{Binding CardCancelData}" />


이런식으로...

유저컨트롤에서 버튼 커맨드를 넣었을때


 <Button Content="확인" Command="{Binding DataContext.CardCancelCommand}"  CommandParameter="Cancel" />


이런식으로 넣으면 안된다. datacontext안에 서 command를 호출하기 때문이다


이렇게 할려면 상위에서 DataContext를 빼야 작동한다.


그러면 상위에서 호출되게 할려면 어떻게 해야할까.


 <Button Content="확인" Command="{Binding Path=DataContext.CardCancelCommand,

                        RelativeSource={RelativeSource Mode=FindAncestor,

                        AncestorType={x:Type local:PopupControl}}}" CommandParameter="Cancel" />


이렇게 하면 된다.

참고 : https://stackoverflow.com/questions/3404707/access-parent-datacontext-from-datatemplate


Posted by 동동(이재동)
Windows Phone 72012. 3. 22. 16:10

실버라이트 툴킷에는 있는데 윈폰 툴킷에는 업어서

내가 만들려는 찰나 찾았따 ㅋ

 

참고 : http://wp7wonders.wordpress.com/2010/10/15/use-the-rating-control-in-windows-phone-7/

Posted by 동동(이재동)