Browse Source

Set combobox items from xaml on ViewboxPage

Wiesław Šoltés 3 years ago
parent
commit
eaa62b7828

+ 17 - 4
samples/ControlCatalog/Pages/ViewboxPage.xaml

@@ -12,8 +12,8 @@
           <Border HorizontalAlignment="Center" Grid.Column="0" BorderThickness="1" BorderBrush="Orange" Width="200" Height="200">
             <Border VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0" BorderThickness="1" BorderBrush="CornflowerBlue" Width="{Binding #WidthSlider.Value}" Height="{Binding #HeightSlider.Value}" >
               <Viewbox
-                  Stretch="{Binding #StretchSelector.SelectedItem}"
-                  StretchDirection="{Binding #StretchDirectionSelector.SelectedItem}">
+                  Stretch="{Binding #StretchSelector.SelectedItem.Content, FallbackValue={x:Static Stretch.Uniform}}"
+                  StretchDirection="{Binding #StretchDirectionSelector.SelectedItem.Content, FallbackValue={x:Static StretchDirection.Both}}">
                 <Ellipse Width="50" Height="50" Fill="CornflowerBlue" />
               </Viewbox>
             </Border>
@@ -25,9 +25,22 @@
             <TextBlock Text="Height" />
             <Slider Minimum="10" Maximum="200" Value="100" x:Name="HeightSlider" TickFrequency="25" TickPlacement="TopLeft" />
             <TextBlock Text="Stretch" />
-            <ComboBox x:Name="StretchSelector" HorizontalAlignment="Stretch" Margin="0,0,0,2" />
+            <ComboBox x:Name="StretchSelector" HorizontalAlignment="Stretch" SelectedIndex="0" Margin="0,0,0,2" >
+              <ComboBox.Items>
+                <ComboBoxItem Content="{x:Static Stretch.Uniform}"/>
+                <ComboBoxItem Content="{x:Static Stretch.UniformToFill}"/>
+                <ComboBoxItem Content="{x:Static Stretch.Fill}"/>
+                <ComboBoxItem Content="{x:Static Stretch.None}"/>
+              </ComboBox.Items>
+              </ComboBox>
             <TextBlock Text="Stretch Direction" />
-            <ComboBox x:Name="StretchDirectionSelector" HorizontalAlignment="Stretch" />
+            <ComboBox x:Name="StretchDirectionSelector" SelectedIndex="0" HorizontalAlignment="Stretch" >
+              <ComboBox.Items>
+                <ComboBoxItem Content="{x:Static StretchDirection.Both}"/>
+                <ComboBoxItem Content="{x:Static StretchDirection.DownOnly}"/>
+                <ComboBoxItem Content="{x:Static StretchDirection.UpOnly}"/>
+              </ComboBox.Items>
+            </ComboBox>
           </StackPanel>
         </Grid>
 

+ 0 - 19
samples/ControlCatalog/Pages/ViewboxPage.xaml.cs

@@ -1,6 +1,5 @@
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
-using Avalonia.Media;
 
 namespace ControlCatalog.Pages
 {
@@ -9,24 +8,6 @@ namespace ControlCatalog.Pages
         public ViewboxPage()
         {
             InitializeComponent();
-
-            var stretchSelector = this.FindControl<ComboBox>("StretchSelector");
-
-            stretchSelector.Items = new[]
-            {
-                Stretch.Uniform, Stretch.UniformToFill, Stretch.Fill, Stretch.None
-            };
-
-            stretchSelector.SelectedIndex = 0;
-
-            var stretchDirectionSelector = this.FindControl<ComboBox>("StretchDirectionSelector");
-
-            stretchDirectionSelector.Items = new[]
-            {
-                StretchDirection.Both, StretchDirection.DownOnly, StretchDirection.UpOnly
-            };
-
-            stretchDirectionSelector.SelectedIndex = 0;
         }
 
         private void InitializeComponent()