How to change button's command to tabcontrols' in wpf - wpf

I have 4 buttons binding commands, I want to use tabcontrols accomplish these commands.
<Button Margin="5" Width="Auto" Height="26" Content="operating" Command="{Binding PCmd}" CommandParameter="{Binding ElementName=frame}"/>
<Button Margin="5" Width="Auto" Height="26" Content="settings" Command="{Binding SettingCmd}" CommandParameter="{Binding ElementName=frame}"/>
<Button Margin="5" Width="Auto" Height="26" Content="showing" Command="{Binding DiCmd}" CommandParameter="{Binding ElementName=frame}"/>
<Button Margin="5" Width="Auto" Height="26" Content="controls" Command="{Binding DeviceCmd}" CommandParameter="{Binding ElementName=frame}"/>
<Frame x:Name="frame" Source="PPage.xaml" NavigationUIVisibility="Hidden" />
settings commmand like this:
SettingCmd = new RelayCommand<System.Windows.Controls.Frame>
(
(f) =>
{
f.Navigate(new Uri(#"View\SettingPage.xaml", UriKind.Relative));
}
);
now I make these changes, how to add commands to them to accomplish the commands in buttons, and there are 4 xaml pages according to 4 buttons
<controls:MetroAnimatedSingleRowTabControl Grid.Row="1" x:Name="MainTabControl">
<TabItem Header="operating"></TabItem>
<TabItem Header="settings"></TabItem>
<TabItem Header="showing"></TabItem>
<TabItem Header="controls"></TabItem>
</controls:MetroAnimatedSingleRowTabControl>

Since there are no need for the frame anymore, the best way is to bring the Xaml of each page and put it inside the corresponding TabItem, for example :
<TabItem Header="settings">
//bring the Xaml of SettingPage.Xaml to here
</TabItem>
In that case they will be no need for navigation and there for no need for commands, but if you insisted on keeping each tab content on a separated Xaml file you must first define a Frame in each TabItem, and set its source property to the coresponding Xaml page :
<controls:MetroAnimatedSingleRowTabControl Grid.Row="1" x:Name="MainTabControl">
<TabItem Header="operating">
<Frame Source="View/OperatingPage.xaml" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
</TabItem>
<TabItem Header="settings">
<Frame Source="View/SettingPage.xaml" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
</TabItem>
<TabItem Header="showing">
<Frame Source="View/ShowingPage.xaml" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
</TabItem>
<TabItem Header="controls">
<Frame Source="View/ControlsPage.xaml" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
</TabItem>
</controls:MetroAnimatedSingleRowTabControl>
in this case also there are no need for any command.

Related

Is it possible to make the contents of a ScrollViewer scroll with the mouse wheel?

I'm on a team of developers working on a new WPF application. We've got a usercontrol on the MainWindow which has a ScrollViewer. We've got VerticalScrollBarVisibility="Auto" set, which works fine, if the contents within the ScrollViewer become larger than the available space for the ScrollViewer. However, what doesn't happen, which I wish would happen, is the user cannot scroll the contents with the mouse wheel. In other places where we're using DataGrids, if the content of the DataGrid is larger than can be displayed vertically, the user can scroll the contents vertically using their mouse wheel. But they cannot do so within the ScrollViewer in the user control on MainWindow. If it's possible to make the contents scroll vertically with the mouse wheel, how is it done?
Here's a snippet of the ScrollViewer, with content removed for brevity:
<ScrollViewer
Grid.Row="1"
Margin="0,20,0,0"
Width="300"
VerticalScrollBarVisibility="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<StackPanel>
<Expander
x:Name="PeopleSideExpander"
IsExpanded="{Binding PeopleSideIsExpanded}"
IsEnabled="True">
<Expander.Header>
<Button
x:Name="tilePeopleSide"
Content="People Side"
Command="{Binding PeopleSideExpanderCommand}"
Cursor="Hand" />
</Expander.Header>
<ListBox>
<ListBoxItem>
<Button Name="tileAgency" Content="Agencies" Command="{Binding ViewAgencyCommand}" />
</ListBoxItem>
<ListBoxItem>
<Button Name="tilePerson" Content="Personnel" Command="{Binding ViewPersonCommand}" />
</ListBoxItem>
<!-- Several other ListBoxItems removed for brevity -->
</ListBox>
</Expander>
<Expander
x:Name="HardwareSideExpander"
Grid.Row="1"
IsExpanded="{Binding HardwareSideIsExpanded}"
IsEnabled="True">
<Expander.Header>
<Button
x:Name="tileHardwareSide"
Content="Hardware Side"
Command="{Binding HardwareSideExpanderCommand}"
Cursor="Hand" />
</Expander.Header>
<ListBox>
<ListBoxItem>
<Button Name="tileEvent"
Content="Event"
IsEnabled="False"
Foreground="LightGray"
Command="{Binding ViewEventCommand}" />
</ListBoxItem>
<ListBoxItem>
<Button Name="tileInstrument"
Content="Instrument"
IsEnabled="False"
Foreground="LightGray"
Command="{Binding ViewInstrumentCommand}" />
</ListBoxItem>
<ListBoxItem>
<Button x:Name="tileHardwareProficiency"
Content="Proficiencies"
Visibility="Collapsed"
ToolTip="Not Implemented" />
</ListBoxItem>
<ListBoxItem>
<Button x:Name="tileSolution"
Content="Proficiency Solutions"
Command="{Binding ViewSolutionCommand}" />
</ListBoxItem>
</ListBox>
</Expander>
</StackPanel>
</ScrollViewer>

How to add command event and pass the current node data in wpf telerik RadTreeviewItem with custom button

I'm using Kendo Telerik RadTreeView control in WPF.. I have functionality that for each RadTreeViewItem, I need to show a button, which i able to do.
Now the button next to each RadTreeViewItem will have event/command which need to open pop window and pass the current node data.
I have tried with code behind button click event and it works fine.. but as per the requirement we should only use command not code behind events.
Here is the code where I'm adding the button..
<HierarchicalDataTemplate x:Key="BuildingStructure"
ItemsSource="{Binding StructureLevels}"
ItemContainerStyle="{StaticResource levelNodeStyle}">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="250"
Text="{Binding Name}"
HorizontalAlignment="Left"/>
<Button
Panel.ZIndex="100"
BorderThickness="0"
BorderBrush="Transparent"
Background="Black"
Grid.Column="1"
VerticalAlignment="Stretch"
Margin="0 2 0 5">
<Image
Width="20"
Height="20"
Source="/Project;component/Resources/Images/03-Add.png"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding TestRadTreeCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</HierarchicalDataTemplate>
Please check the image for your Reference :
Thanks in advance...!!
The Button has a Command property so there is no reason to use an EventTrigger and an InvokeCommandAction to handle the MouseLeftButtonDown event.
If TestRadTreeCommand is defined in the view model, i.e. the DataContext of the TreeView, you could bind to it like this:
<Button
Panel.ZIndex="100"
BorderThickness="0"
BorderBrush="Transparent"
Background="Black"
Grid.Column="1"
VerticalAlignment="Stretch"
Margin="0 2 0 5"
Command="{Binding DataContext.TestRadTreeCommand, RelativeSource={RelativeSource AncestorType=TreeView}}">
<Image Width="20"
Height="20"
Source="/CCRIS;component/Resources/Images/03-Add.png"/>
</Button>

Viewbox TabControl sizing gets messed up depending on font size

I have a program that lets you edit different properties so that you can edit a different control.
I'm trying to get the layout right for the editor but I can't seem to get it easily.
I have put it in a viewbox so it sizes according to the screen. This is the XAML for the editor:
<Viewbox Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" HorizontalAlignment="Center">
<TabControl Background="{DynamicResource CustomOrange}">
<TabItem Header="Background" Visibility="Visible" FontSize="10">
<StackPanel>
<DockPanel LastChildFill="False">
<Label Content="Background" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Background Image" DockPanel.Dock="Left"/>
<Button Content="Find Image" DockPanel.Dock="Right"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Show Text" DockPanel.Dock="Left"/>
<CheckBox Content="Find Image" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DockPanel>
</StackPanel>
</TabItem>
<TabItem Header="Button" Visibility="Visible">
<StackPanel>
<DockPanel LastChildFill="False">
<Label Content="Background IMAGE" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Background Image" DockPanel.Dock="Left"/>
<Button Content="Find Image" DockPanel.Dock="Right"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Show Text" DockPanel.Dock="Left"/>
<CheckBox Content="Find Image" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DockPanel>
</StackPanel>
</TabItem>
</TabControl>
</Viewbox>
The problem is that the first TabItem looks like this:
But because I have changed the content of the label, the second TabItem looks like this:
Now, I know there are simpler ways to do this, but the problem is I don't know for sure how many options I am implementing for the user (Width, Height, Location, Font, Background, Content etc).
I have done it before with a grid but the problem is anytime I remove an option then all of them need to be re-done so that they are all in the exact Grid.Row which is why I am using StackPanel for the rows, and I am using the DockPanel so they keep separated horizontally
Thank you!!!

Children Tabs in Wpf

I have been looking for a way to implement a child tab control inside a tab control(sort of like multi level tab controls).
but haven't found any materials for that, i can implement dynamically that at run time in Xaml.cs though, but i want to define it into Window.Xaml only, so that i can embed my controls into it.
Figure Below is an sample of the ui.
Kindly Suggest me the way to do it.
This will work for you.
<TabControl>
<TabItem Header="Tab1">
<TabControl Margin="10">
<TabItem Header="Tab1">
<TabControl Margin="20">
<TabItem Header="Tab1">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<DockPanel >
<TextBlock Text="Name:" VerticalAlignment="Center" DockPanel.Dock="Left"></TextBlock>
<TextBox Text="Nitesh" Margin="10,0,0,0" DockPanel.Dock="Right"></TextBox>
</DockPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<Button Margin="5">OK</Button>
<Button Margin="5">Cancel</Button>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="Tab2"></TabItem>
</TabControl>
</TabItem>
<TabItem Header="Tab2"></TabItem>
</TabControl>
</TabItem>
<TabItem Header="Tab2"></TabItem>
</TabControl>

DropDownButton content binding issue

I'm trying to add MenuItems into a DropDropButton control and control the visibility
of the buttons using the IsSelected property of TabItem, however the visibility
of the MenuItems do not change. I applied the same binding on a standard
button it the visibility works as expected. Does anyone know what is going on here?
Here is a sample of what I'm trying to do:
<StackPanel>
<Button Content="Hi" Visibility="{Binding ElementName=tabItem1, Path=IsSelected, Converter={StaticResource VisibilityConverter}}"/>
<toolkitEx:DropDownButton Content="Button 1">
<toolkitEx:DropDownButton.DropDownContent>
<StackPanel>
<MenuItem Header="Visibile for tabItem1" Visibility="{Binding ElementName=tabItem1, Path=IsSelected, Converter={StaticResource VisibilityConverter}}"/>
<MenuItem Header="Visibile for tabItem2" Visibility="{Binding ElementName=tabItem2, Path=IsSelected, Converter={StaticResource VisibilityConverter}}"/>
</StackPanel>
</toolkitEx:DropDownButton.DropDownContent>
</toolkitEx:DropDownButton>
<TabControl HorizontalAlignment="Stretch" Name="tabControl1" VerticalAlignment="Stretch" >
<TabItem Header="tabItem1" x:Name="tabItem1">
<Grid />
</TabItem>
<TabItem Header="tabItem2" x:Name="tabItem2">
<Grid />
</TabItem>
</TabControl>
</StackPanel>
Thanks!

Resources