I am trying to create a flyout for settings using MahApps.Metro inside of a MetroWindow control using WPF. I have created the flyout and have several other radio buttons and seperators. I am now adding a datagrid to hold a list of StockSymbols used as a watch list for my application. What I am having trouble with is properly setting the datagrid so that it does not autogrow past the size of the flyout. If you add rows to the datagrid you can keep adding until it flows offscreen ouside of the window. I would like to do it so that I don't have to manually set the max Height and for it to dynamically grow as the window grows.
Here is my current code for the flyout:
<Controls:MetroWindow.Flyouts>
<Controls:Flyout Header="Settings"
Background="#9f000000"
Position="Right"
IsOpen="{Binding IsSettingsFlyoutOpen}">
<DockPanel HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<StackPanel Orientation="Vertical"
VerticalAlignment="Top"
HorizontalAlignment="Center"
Margin="20,0"
DockPanel.Dock="Top">
<Label Content="Theme"
Style="{StaticResource DescriptionHeaderStyle}" />
<StackPanel Orientation="Horizontal">
<RadioButton Content="Dark"
Margin="0,0,5,0"
IsChecked="True"
Checked="ThemeDark" />
<RadioButton Content="Light"
Margin="0,0,5,0"
Checked="ThemeLight" />
</StackPanel>
<Separator Margin="0,10,0,10" />
<Label Content="Accent"
Style="{StaticResource DescriptionHeaderStyle}" />
<StackPanel Orientation="Vertical">
<RadioButton Content="Black"
Margin="0,5,0,0" />
<RadioButton Content="Blue"
Margin="0,5,0,0"
Checked="AccentBlue" />
<RadioButton Content="Red"
Margin="0,5,0,0"
Checked="AccentRed" />
<RadioButton Content="Green"
Margin="0,5,0,0"
Checked="AccentGreen" />
<RadioButton Content="Orange"
Margin="0,5,0,0"
IsChecked="True"
Checked="AccentOrange" />
<RadioButton Content="Purple"
Margin="0,5,0,0"
Checked="AccentPurple" />
</StackPanel>
<Separator Margin="0,10,0,10" />
</StackPanel>
<StackPanel Orientation="Vertical"
Height="Auto"
VerticalAlignment="Top"
DockPanel.Dock="Bottom"
Margin="20,0">
<Label Content="Watch List"
Style="{StaticResource DescriptionHeaderStyle}" />
<DataGrid ItemsSource="{Binding WatchList}"
AutoGenerateColumns="False"
CanUserResizeRows="False"
CanUserReorderColumns="False"
HeadersVisibility="Column">
<DataGrid.Columns>
<DataGridTextColumn Header="Symbol"
Binding="{Binding Symbol}" />
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DockPanel>
</Controls:Flyout>
</Controls:MetroWindow.Flyouts>
Any and all help is appreciated.
I solved this question by using only a Dock Panel to hold all the controls inside the Flyout. The all controls but the data grid should be set to top docking and no docking set on the datagrid. This then auto sizes the datagrid to fill the remaining space and no more.
I had the same problem.
I solved this issue setting the Flyout size.
I think the problem occurs when WPF render the grid and the Flyout size is smaller than grid size.
anyway, our Flyout was dynamic, I had to create a Converter to get its size and set my child control to same width
Related
Got this XAML for my Data Binded Label:
<ItemsControl
Name="itClblArtiksel"
ItemsSource="{Binding ArtikelInfo}"
Margin="925,45,0,0"
Width="89"
Height="31"
HorizontalAlignment="Left"
VerticalAlignment="Top"
BorderThickness="1"
BorderBrush="Black"
FontWeight="Bold"
>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label
x:Name="lblArtikelNr"
Content="{Binding ArtNr}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
i already tried to set the VerticalContentAlignment of the ItemsControl and Label to Center but the content dont get centered... any ideas?
EDIT
Picture to demonstrate the situation:
as you can see the bold one (so the one with <itemcontrol>) are in the air
EDIT 2
The accepted answer gave me the final solution:
<ItemsControl Name="itClblArtiksel" ItemsSource="{Binding ArtikelInfo}" VerticalContentAlignment="Center" Height="37" Margin="925,45,236,38" BorderThickness="1" BorderBrush="Black" FontWeight="Bold">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="37">
<Label
VerticalAlignment="Center"
x:Name="lblArtikelNr"
Content="{Binding ArtNr}"
/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
setting a Grid around the Label with the same Height as the ItemsControland setting then the VerticalAlignment to Center was the workaround.
This will center the labels vertically within their parents. In your case, this will have no effect because the items are only as tall as their content.
<DataTemplate>
<Label
VerticalAlignment="Center"
x:Name="lblArtikelNr"
Content="{Binding ArtNr}"
/>
</DataTemplate>
If you want them to be visibly centered vertically, you need to give them room for that to happen:
<DataTemplate>
<Grid Height="100">
<Label
VerticalAlignment="Center"
x:Name="lblArtikelNr"
Content="{Binding ArtNr}"
/>
</Grid>
</DataTemplate>
But since your ItemsControl has a fixed height of 31, this will simply make the items larger than their parent, pushing the label out of sight. You need to remove that. I also urge you to consider getting accustomed to using StackPanel and Grid for layout, rather than setting very large margins on everything. The margins method makes it hard to rearrange your UI.
How about setting the VerticalAlignment property of the Label to Center?
<Label x:Name="lblArtikelNr" Content="{Binding ArtNr}" VerticalAlignment="Center" />
This works for me:
<ItemsControl
BorderThickness="1"
BorderBrush="Black"
FontWeight="Bold">
<ItemsControl.Items>
<system:String>wefwefwefwe</system:String>
<system:String>wefwefwefwe</system:String>
<system:String>wefwefwefwe</system:String>
<system:String>wefwefwefwe</system:String>
</ItemsControl.Items>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type system:String}">
<Label Height="50" Foreground="Black" Content="{Binding}" BorderThickness="1"
BorderBrush="Black" VerticalContentAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<RibbonWindow x:Class="xxx.yyy"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
<Ribbon x:Name="mainRibbon" Grid.Row="0" >
...
<RibbonTab Name="ComparisonTab" HorizontalContentAlignment="Left" Header="Comparison" >
<!--<StackPanel Orientation="Vertical" HorizontalAlignment="Left">-->
<RibbonGroup HorizontalContentAlignment="Left" Header="Images" >
<RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo1Check}" Label="{Binding CompInfo1Text}" />
<RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo2Check}" Label="{Binding CompInfo2Text}" />
<RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo3Check}" Label="{Binding CompInfo3Text}" />
</RibbonGroup>
<!--</StackPanel>-->
</RibbonTab>
I have some checkboxes with a dynamic text (labels) and I want to have them left aligned within a ribbon group.
I've tried every imaginable combination of Horizontal(Content)Alignment on them and on their parents. I tried to put them into a container (StackPanel, Grid). I even tried to set a label as a separate element.
The checkboxes stubbornly remain centered within a ribbon group. How do I align them horizontally to the left?
I've found a workaround in using standard check boxes inside a ribbon. There is no problem with their alignment. They could be styled to look as the ribbon check boxes, if required.
So, the modified xaml is:
<RibbonTab Name="ComparisonTab" HorizontalContentAlignment="Left" Header="Comparison" >
<RibbonGroup Header="Images" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<CheckBox Height="25" IsChecked="{Binding CompInfo1Check}" Content="{Binding CompInfo1Text}" />
<CheckBox Height="25" IsChecked="{Binding CompInfo2Check}" Content="{Binding CompInfo2Text}" />
<CheckBox Height="25" IsChecked="{Binding CompInfo3Check}" Content="{Binding CompInfo3Text}" />
</StackPanel>
</RibbonGroup>
</RibbonTab>
EDIT
Probably a better way is to use a grid, RibbonCheckBox without a label and a TextBlock instead.
Explained here.
In WPF, I am using the MVVM model.
I have a View with a Dockpanel and I want to add dynamically StackPanels with a Label and TextBox for all Harddisks found over the Binding.
Therefore my XAML looks like:
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch" Margin="5">
<ItemsControl ItemsSource="{Binding Harddisks}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="2.5,0,0,0">
<Label Content="{Binding Path=Label}" />
<TextBox Text="{Binding Path=GB_Free}" Width="100" IsReadOnly="True"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
It should be four Labels and TextBoxes, but only the first Label and TextBox are shown.
Why?
Your items in your ItemsControl are not actually direct children of the DockPanel. You need to change the ItemsControl to specify that the DockPanel is the Panel. The following will cause the ItemsControl to create a DockPanel and place all the items inside it (rather than the StackPanel that ItemsControl uses by default).
More Info: MSDN: ItemsControl.ItemsPanel Property
<ItemsControl ItemsSource="{Binding Harddisks}">
<ItemsControl.ItemsPanel>
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch" Margin="5" />
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="2.5,0,0,0">
<Label Content="{Binding Path=Label}" />
<TextBox Text="{Binding Path=GB_Free}" Width="100" IsReadOnly="True"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I would like to add a preloader to a ListBox, I already added a preloader to the whole pivot control, but I only show it for one listbox (I have a listbox for each pivot page) I wish to create separate preloaders for each listbox, has any one done this?
I currently have a preloader control, showing the loading text and progress bar
Is there any way I can attach a progress bar to the listbox, and show it until the data is loaded from the webservice (For each different listbox)?
This is my current preloader:
code preview of my list in xaml
<telerikPrimitives:RadDataBoundListBox HorizontalAlignment="Left" Margin="4,0,0,0" Name="listNearbyBusinesses" IsAsyncBalanceEnabled="True" AsyncBalanceMode="FillViewportFirst" SelectionChanged="listNearbyBusinesses_SelectionChanged" Height="535" VerticalAlignment="Top" Grid.RowSpan="2" Grid.ColumnSpan="2">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="100" Height="100" x:Name="m_Image" Source="{Binding Image}"/>
<StackPanel>
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
<TextBlock Text="{Binding Type}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" />
<telerikInput:RadRating IsReadOnly="True" Value="{Binding Rating}" Margin="12" ItemShapeHeight="20" ItemShapeWidth="20" />
</StackPanel>
</StackPanel>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>
I'm having an issue with tabbing through the controls on a WPF application using the MVVM pattern. I have the following XAML which defines a tree structure
<Grid Background="Transparent" Margin="10">
<TreeView ItemsSource="{Binding FirstLevelNavigableViewModels}" Background="Transparent"
HorizontalContentAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderThickness="0"
ItemContainerStyle="{StaticResource TreeViewItemStyle1}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type ViewModel:VendorViewModel}" ItemsSource="{Binding Children}">
<View:VendorView HorizontalContentAlignment="Stretch" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type ViewModel:ProductViewModel}">
<View:ProductView HorizontalContentAlignment="Stretch" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
When the treeview is loaded, the XAML for the "ProductView" is as follows
<Border Margin="0,2,2,2" CornerRadius="3" Background="#3FC7B299" DockPanel.Dock="Right" HorizontalAlignment="Right" Width="109">
<StackPanel Orientation="Vertical" Margin="6,4">
<DockPanel>
<TextBlock DockPanel.Dock="Left" FontFamily="Segoe" FontSize="10" FontWeight="Medium"
Foreground="Black" Opacity="0.75"
Text="CALC. REG. PRICE"></TextBlock>
<Button Width="10" Height="10" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Padding="-4" Margin="0" Command="{Binding UserDefinedRetailPriceCommand}" Visibility="{Binding UserDefinedRetailPriceButtonView}">
<Image Width="10" Height="10" Source="/Arhaus.Pricing.Client;component/Styles/Images/error.png"></Image>
</Button>
</DockPanel>
<TextBox FontFamily="Segoe" FontSize="16" FontWeight="Medium" KeyboardNavigation.IsTabStop="True" KeyboardNavigation.TabIndex="{Binding RegularPriceTabIndex}"
Foreground="Black" Opacity="0.9" KeyboardNavigation.TabNavigation="Continue"
ebf:LostFocusBehaviour.LostFocusCommand = "{Binding LostFocusSugg}"
Text="{Binding NewSuggestedRetailPrice,Converter={StaticResource FormattingConverter}, ConverterParameter=' \{0:C\}', Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Background="#FFE6DED3" BorderBrush="#FFE6DED3" DataContext="{Binding StringFormat=\{0:c\}, NotifyOnValidationError=True}" Padding="0" TabIndex="1"></TextBox>
</StackPanel>
</Border>
I have the Tab Index bound to an integer that is ever increasing and bound as the treeview is loaded (I.E. I have it setup as tab index 1, 2, 3 etc. as each successive model is loaded).
I would like to be able to hit tab and jump to the next textbox in the treeview but when I click the TAB key, nothing happens. I'm not sure if I have the tabbing setup correctly but I'm very new to WPF and at a loss as to where and how to set the tabbing to make it work. I'm used to WinForms where you just set the tab index and go from there.
Thank you for your assistance, I apologize for the large code block.
I don't have a solution ready but some thoughts that maybe may help:
I don't know what RegularPriceTabIndex returns but probably it begins for each new TreeViewItem at the same index?
The same tab-index is given then multiple times because of repeating use of ProductView. Perhaps this leads to a problem. You can try setting FocusManager.IsFocusScope="true" for the ProductView. Maybe this helps.
Try also to set Control.IsTabStop="true" on the TextBox.