Advertisement
Guest User

Untitled

a guest
Jan 15th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. public class ComboBoxData : BaseViewModel
  2.     {
  3.         private Brush _labelsColor;
  4.         private string _textConst;
  5.  
  6.         public Brush LabelsColor
  7.         {
  8.             get => _labelsColor;
  9.             private set => Set(ref _labelsColor, value);
  10.         }
  11.  
  12.         public string TextConst
  13.         {
  14.             get => _textConst;
  15.             private set => Set(ref _textConst, value);
  16.         }
  17.  
  18.         public ComboBoxData(Brush color, string text)
  19.         {
  20.             LabelsColor = color;
  21.             TextConst = text;
  22.         }
  23.     }
  24.  
  25.  
  26. //===========================================
  27.  
  28. public class EditTaskWindowViewModel : BaseViewModel
  29.     {
  30.         private List<ComboBoxData> _cbData;
  31.         private ComboBoxData _cbSolo;
  32.  
  33.         public ComboBoxData cbSolo
  34.         {
  35.             get => _cbSolo;
  36.             set => Set(ref _cbSolo, value);
  37.         }
  38.  
  39.         public List<ComboBoxData> CBData
  40.         {
  41.             get => _cbData;
  42.             set => Set(ref _cbData, value);
  43.         }
  44.  
  45.         public EditTaskWindowViewModel()
  46.         {
  47.             CBData = new List<ComboBoxData>();
  48.             InitializecbData(0, 148, 204, "Will definitely happen"); //new Color(#0094cc)
  49.             InitializecbData(0, 178, 72, "Need to do"); //Brushes(#00b248)
  50.             InitializecbData(249, 168, 37, "It is desirable to do"); //Brushes(#f9a825)
  51.         }
  52.  
  53.         private void InitializecbData(byte r, byte g, byte b, string text)
  54.         {
  55.             Color tmpColor = new Color();
  56.             tmpColor.G = g;
  57.             tmpColor.R = r;
  58.             tmpColor.B = b;
  59.             SolidColorBrush tmpSolidBrush = new SolidColorBrush(tmpColor);
  60.             Brush tmpBrush = tmpSolidBrush;
  61.  
  62.             ComboBoxData cbd = new ComboBoxData(tmpBrush, text);
  63.             CBData.Add(cbd);
  64.         }
  65.     }
  66.  
  67. //===========================================
  68.  
  69. <ComboBox Height="28" Margin="50,48,25,124" ItemsSource="{Binding CBData}" SelectedItem="{Binding cbSolo}">
  70.             <ComboBox.ItemTemplate>
  71.                 <DataTemplate>
  72.                     <StackPanel Orientation="Horizontal">
  73.                         <Rectangle Height="10" Width="10" Margin="3, 0">
  74.                             <Rectangle.Fill>
  75.                                 <SolidColorBrush Color="{Binding LabelsColor}"/>
  76.                             </Rectangle.Fill>
  77.                         </Rectangle>
  78.                         <TextBlock Text="{Binding TextConst}"></TextBlock>
  79.                     </StackPanel>
  80.                 </DataTemplate>
  81.             </ComboBox.ItemTemplate>
  82.         </ComboBox>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement