MVVM multiple textboxes one command - c#

I have four of the same StackPanels in a Grid Layout. (See one of them below)
Is it possible to implement this easier?
How I can get all values or changes from Textboxes in the StackPanel(s)?
Is it possible to bind one Command in the panel to get the changes in the ViewModel?
I think the answer is anything with ItemControl?!
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="2" Margin="50, 90, 0, 0" Height="auto" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="10,0,0,0"/>
<Setter Property="MinWidth" Value="80"/>
<Setter Property="MinHeight" Value="60"/>
</Style>
</StackPanel.Resources>
<Label Content="2" Width="60" Height="60" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</StackPanel>

Related

What panels and containers allow Overlapping of UI elements

What are the panels and containers that allow overlapping with varying z-index ? (escluding Canvas)
--Since I was asked for details this is part of the code:
<DockPanel HorizontalAlignment="Left" Height="32" LastChildFill="False" Margin="10,0,0,10"
VerticalAlignment="Top">
<Rectangle Fill="{Binding (extensions:PaletteColor.FillBrush)}" Height="32" RadiusY="4"
RadiusX="4"
Stroke="#FF000000" Width="32" HorizontalAlignment="Left" VerticalAlignment="Top"
MouseLeftButtonUp="TargetColorClick"
ToolTip="{Binding (extensions:PaletteColor.Name)}" />
Ok I was able to do this with Clemens support:
<TextBlock TextWrapping="Wrap" Text="16"
Margin="-32,0,0,0" Height="16"
HorizontalAlignment="Center" />
--Answering to another question my XAML for whole control looks like this:
<ItemsControl ItemsSource="{Binding (local:MainWindow.CurrentPaletteSet)}" Width="400" Margin="665,67,14,-67">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel HorizontalAlignment="Left" Height="32" LastChildFill="False" Margin="10,0,0,10"
VerticalAlignment="Top">
<Rectangle Fill="{Binding (extensions:PaletteColor.FillBrush)}" Height="32" RadiusY="4"
RadiusX="4"
Stroke="#FF000000" Width="32" HorizontalAlignment="Left" VerticalAlignment="Top"
MouseLeftButtonUp="TargetColorClick"
ToolTip="{Binding (extensions:PaletteColor.Name)}" />
<TextBlock TextWrapping="Wrap" Text="16"
Margin="-32,0,0,0" Height="16"
HorizontalAlignment="Center" />
<TextBlock TextWrapping="Wrap" Text="{Binding (extensions:PaletteColor.FullRgbString)}"
Margin="5,0,0,0" Height="16"
HorizontalAlignment="Left" DockPanel.Dock="Top" />
<TextBlock TextWrapping="Wrap" Text="{Binding (extensions:PaletteColor.FullHslString)}"
Margin="5,0,0,0"
Height="16" HorizontalAlignment="Left" DockPanel.Dock="Top" MinWidth="121" />
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel></ItemsControl>

Expand and Collapse a WPF Expander

I have two Expanders in a DockPanel control, the first Expander that is at the top is set to isExpanded true while the other Expander is not.
I just want the second Expander to go up whenever the first Expander is set to isExpanded false in run time...
Here is my XAML code :
<DockPanel LastChildFill="False" Margin="0,26,0,0" Background="#FF552D2D" HorizontalAlignment="Left" Width="149">
<StackPanel ScrollViewer.VerticalScrollBarVisibility="Auto">
<Expander x:Name="AdminManage" Header="Manage" Margin="0" Foreground="#FF14D0EE" Height="198" IsExpanded="True" Collapsed="AdminManage_Collapsed" Width="544">
<StackPanel x:Name="AdminStackPanel" Height="177" Margin="0,0,-2,0">
<Button Content="" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" Margin="23,0,0,0" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66">
<StackPanel Height="44" Margin="0,0,-2,0">
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
<Button Content="" Margin="23,0,0,0" Background="#FF552D2D" BorderBrush="{x:Null}" BorderThickness="0" Opacity="0.5" Foreground="White" VerticalAlignment="Center" HorizontalContentAlignment="Left" HorizontalAlignment="Left" Width="124"/>
</StackPanel>
</Expander>
</StackPanel>
</DockPanel>
Remove your Height property from AdminManage Expander, i test it it will work like expected
By go below do you mean to expand the expander ?
If so, you can do a element binding like below. You also need a converter to invert the Boolean value of the first expander.
<Expander Header="Account" Margin="0" VerticalAlignment="Top" Foreground="#FF14D0EE" Height="66"
IsExpanded="{Binding IsExpanded, ElementName=AdminManage, Converter={StaticResource InvertBooleanConverter}"
<StackPanel Height="44" Margin="0,0,-2,0">
<!-- your content here -->
</StackPanel>
</Expander>
Else if you meant to interchange their positions you would want to add the expanders inside a Grid instead of a StackPanel and change the attached Grid.Row property of the expanders whenever IsExpanded changes

Button as HyperlinkButton

Instead of creating a HyperlinkButton to navigate to other page in a frame, i want to use the Button. I have this HyperlinkButton
<HyperlinkButton NavigateUri="/MyPageName" TargetName="mainFrame" Content="Go To My Page" />
i think it is possible and i have this so far
<Button x:Name="btnView" Content="View">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<!-- and i dont know what is next here -->
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
any help would be aprreciated..
TIA
Design the contents of the HyperlinkButton.
<HyperlinkButton Name="btn" Margin="340,5,0,0" Background="Transparent" Height="48" VerticalAlignment="Top" Padding="2,0,2,2" BorderBrush="Transparent" Foreground="Black" HorizontalAlignment="Left" Width="110">
<HyperlinkButton.Content>
<Grid>
<Rectangle Fill="#FFC1B7B7" HorizontalAlignment="Stretch" Margin="0" RadiusX="4" RadiusY="4" Stroke="#FF1D1212" StrokeThickness="2" Width="Auto" Grid.Column="1" VerticalAlignment="Top" Height="43" />
<TextBlock Text="NONE" FontSize="16" Height="20" HorizontalAlignment="Left" Margin="0" Name="tb" Padding="2" VerticalAlignment="Bottom" Width="110" FontFamily="Courier New" FontWeight="Bold" Grid.Column="1" TextAlignment="Center" />
</Grid>
</HyperlinkButton.Content>
</HyperlinkButton>

Switching between landscape and portrait mode using wpf in tablet devices

How could we arrange the controls on a WPF window so that it would automatically align the controls while switching between view modes occur ie between landscape and portrait mode.
<Window x:Class="Custom_Track_Reports.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginWindow" >
<Viewbox Stretch="Fill">
<Grid Background="#FF58B0DF" Height="401">
<Rectangle Fill="#FFF0F3F4" Height="173" Margin="45,197,58,0" Stroke="Black" VerticalAlignment="Top" AllowDrop="True" />
<Image Height="125" Margin="340,10,330,0" VerticalAlignment="Top" Source="Images/logo_lrg.png"/>
<Label Content="Custom Track Reports" HorizontalAlignment="Left" Margin="287,147,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.607,1.112" Width="268" Height="47" FontFamily="Arial" FontSize="26" Foreground="White"/>
<TextBox Margin="128,0,0,110" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="25" BorderThickness="1" FontFamily="Arial" FontSize="21" Text="" Name="userTextBox" FontStretch="Expanded" Opacity="1" HorizontalAlignment="Left" Width="546" AcceptsReturn="False" KeyDown="userTextBox_KeyDown" />
<Button x:Name="enterButton" Content="Enter" HorizontalAlignment="Right" Margin="0,311,166,0" VerticalAlignment="Top" Width="110" Height="26" FontSize="14" Style="{DynamicResource button}" Click="enterButton_Click"/>
<Label Content="User ID" FontSize="20" FontWeight="Bold" Height="40" HorizontalAlignment="Left" Margin="122,215,0,0" Name="label1" VerticalAlignment="Top" Width="105" />
</Grid>
</Viewbox>

Scrollviewer having issues with Dockpanel

I'm using a Dockpanel as my main panel for my layout. The toolbar on top is set to top, while the side panel is set to left. The documentviewer is set to fill by LastChildFill.
The problem is that the height of the scrollviewer doesn't scale as the window resizes. Only the documentviewer does. It seems to only scale as the child content increases. I'm trying to mimic Google Chrome's Print layout. When the children does not overflow the window then there is no scrollbar but if it's less than the window, the scrollbars would fill up the window.
Here's the code:
<ToolBar Width="Auto" Height="35" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" Panel.ZIndex="10" Background="White">
<StackPanel Margin="5,0,0,0" Orientation="Horizontal">
<Button Content="New" Style="{StaticResource MenuItem}"/>
<Button Content="Save" Style="{StaticResource MenuItem}"/>
<Button Content="Print" Style="{StaticResource MenuItem}"/>
<Button Content="Delete" Style="{StaticResource MenuItem}"/>
<Button Content="Export" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Burn DVD" Style="{StaticResource MenuItem}"/>
<Button Content="Open Folder" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Next Patient" Style="{StaticResource MenuItem}"/>
</StackPanel>
</ToolBar>
<ScrollViewer Background="White" x:Name="SidePanel" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="400" DockPanel.Dock="Left" Panel.ZIndex="2" Padding="10">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,10,0,0"/>
</Style>
</StackPanel.Resources>
<Label Content="Patient Report" Style="{StaticResource SidePanel_H1}" />
<Rectangle Style="{StaticResource SidePanel_HR}" />
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
</StackPanel>
</ScrollViewer>
<Rectangle Height="Auto" Width="2" DockPanel.Dock="Left" Fill="#FFA0A0A0"/>
<DocumentViewer x:Name="dv1" AllowDrop="False" Cursor="Hand" Loaded="dv1_Loaded" MinWidth="600">
<FixedDocument Focusable="False" x:Name="FD">
</FixedDocument>
</DocumentViewer>
</DockPanel>
Set VerticalAlignment="Stretch" or remove the attribute and you'll be fine.
DockPanel affects only one direction for docked children. In your case, it's horizontal.

Categories