![]() get_Key_Value_from_String_as_Date(sPanelName, "DatePlan" ) ĬlsSchichtplan. get_Key_Value_from_String_as_Integer(sPanelName, "PosNrBesetzung" ) ĭateTime DatePlan = clsStrings. get_Key_Value_from_String_as_Integer(sPanelName, "IDSchicht" ) get_Key_Value_from_String_as_Integer(sPanelName , "IDMaschine" ) Private void Target_Border_Drop( object sender, DragEventArgs e)īorder target_Control = ( Border )sender get_Key_Value_from_String_as_Integer(sControlname, "IDMitarbeiter" ) String sName = ( string ) button.Content Private void Start_Drag_Event( object sender, MouseButtonEventArgs e) Int IDMitarbeiter = ( int ) e.Data.GetData( "IDMitarbeiter" ) String sName = ( String )e.Data.GetData( "Name" ) String sColor = ( String )e.Data.GetData( "Farbe" ) Ĭolor color = ( Color ) ColorConverter. Move) Įvent, the DragObject is read out directly DoDragDrop(button, dataObj, DragDropEffects. *set informations to the dragged objectĭataObj.SetData( "IDMitarbeiter" , IDMitarbeiter) ĭragDrop. Of the Drag-Operation is then created a DragObject and this object is then Drop += new DragEventHandler (Target_ Border_Drop) That is on eIn drag process should rule then needs the property. PreviewMouseLeftButtonDown += new MouseButtonEventHandler ( Start_Drag_Event) PreviewMouseLeftButtonDown EventĪdded as an event in Xaml or as here at runtime as here to an event methodītnMitarbeiter_Schicht. Operation, any data can be transmitted at runtime.Ĭreate a drag process, all freely definable information is placed in aĭefined information can then be read out by the drag object at the target as inīutton element to be pulled requires one. O.SetValue(IsFavoriteProperty, e.C # Code example shows the simple creation of a drag and drop function in WPFĮxample, a rectangular planning field (WPF button) is drawn into a planning Public static readonly DependencyProperty IsFavoriteProperty =ĭependencyProperty.RegisterAttached("IsFavorite", typeof(bool), typeof(Button), new PropertyMetadata(false, (o, e) =>īutton.Background = (SolidColorBrush) īutton.Foreground = (SolidColorBrush) Public static void SetIsFavorite(DependencyObject obj, bool value) Return (bool)obj.GetValue(IsFavoriteProperty) Public static bool GetIsFavorite(DependencyObject obj) Here is a simple example: public class IsFavoriteBehavior Useful if more than one property should be changed or if one needs access to the view model (through the DataContext of the control) to decide how to change the user interface properties. Public object ConvertBack(object value, Type targetType, object parameter, string language)Īn alternative to converters are attached properties. Return (value is bool & (bool)value) ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Green) Public object Convert(object value, Type targetType, object parameter, string language) For example: public class BooleanToColorConverter : IValueConverter You just need to create a converter which converts Boolean to SolidColorBrush. You can check my previous answer in the following link. I was able to make it work for one button only using the VisualStateManager manager: īut with multiple buttons that bind to different properties in the view model this approach is not working. What is the best approach to change the background color of the buttons using data binding when the corresponding property in the view model is changed? Private void ButtonC_Click(object sender, RoutedEventArgs e) Private void ButtonB_Click(object sender, RoutedEventArgs e) With this code behind private void ButtonA_Click(object sender, RoutedEventArgs e) Without data triggers, how can I change the background color of a button using xaml and data binding only when a boolean property in the view model changes? Universal windows apps don't support data triggers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |