wpf-controls interview questions
Top wpf-controls frequently asked interview questions
I followed this small "tutorial" on how to add a scrollbar to an ItemsControl, and it works in Designer view, but not when I compile and execute the program (only the first few items show up, and no scrollbar to view more - even when VerticalScrollbarVisibility is set to "Visible" instead of "Auto").
Any idea on how to solve this?
This is the code I use to show my items (normally I work with Databinding, but to see the items in my Designer I added them manually):
<ItemsControl x:Name="itemCtrl" Style="{DynamicResource UsersControlStyle}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Top">
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<uc:UcSpeler />
<uc:UcSpeler />
<uc:UcSpeler />
<uc:UcSpeler />
<uc:UcSpeler />
</ItemsControl>
And this is my Template:
<Style x:Key="UsersControlStyle" TargetType="{x:Type ItemsControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<ScrollViewer VerticalScrollBarVisibility="Visible">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Source: (StackOverflow)
Do you know any controls inherited from the ItemsControl that have horizontal orientation of items?
Source: (StackOverflow)
Creating a relatively simple data entry form, and just want to separate certain sections with a horizontal line (not unlike an HR tag in HTML) that stretches the full length of the form.
I have tried this:
<Line Stretch="Fill" Stroke="Black" X2="1"/>
Because the parent control is not a fixed width, this line causes the window to stretch to the full width of the screen.
Is there an easy way to do this without fixing the width of my parent control/window?
Source: (StackOverflow)
I need a button-like control that can have a Checked property, so that when clicked it stays pressed.
I had that functionality in WinForms, with the CheckBox control, setting the Appearance property to "Button".
Can someone help me?
Source: (StackOverflow)
What is the difference between WPF's ListBox and ListView? I can not find any significant difference in their properties. Is there different typical use?
Source: (StackOverflow)
I am using DataGrids in XAML (not Silverlight) with resizable columns, the DataGrid will expand if the user resizes the screen.
Currently if the widths of all the DataGrid columns are less than the width of the DataGrid I get an extra "column" appearing which is unclickable and serves no purpose.
Does anyone know how to make one column always resize to fill all the remaining space?
Source: (StackOverflow)
I'm going to add a WPF Ribbon UI to my program.
What is the best suite of WPF controls including a ribbon control, based on your experiences?
Thanks!
Source: (StackOverflow)
I'm pretty much new to the MVVM architecture design...
I was struggling lately to find a suitable control already written for such a purpose but had no luck, so I reused parts of XAML from another similar control and got make my own.
What I want to achieve is:
Have a reusable View (usercontrol) + viewmodel (to bind to) to be able to use inside other views as a modal overlay showing a dialog that disables the rest of the view, and shows a dialog over the it.

How I wanted to implement it:
- create a viewmodel that takes string(message) and action+string collection(buttons)
- viewmodel creates a collection of ICommands that call those actions
- dialog view binds to the its viewmodel that will be exposed as property of another viewmodel (parent)
- dialog view is put into the xaml of the parent like this:
pseudoXAML:
<usercontrol /customerview/ ...>
<grid>
<grid x:Name="content">
<various form content />
</grid>
<ctrl:Dialog DataContext="{Binding DialogModel}" Message="{Binding Message}" Commands="{Binding Commands}" IsShown="{Binding IsShown}" BlockedUI="{Binding ElementName=content}" />
</grid>
</usercontrol>
So here the modal dialog gets the datacontext from the DialogModel property of the Customer viewmodel, and binds commands and message. It would be also bound to some other element (here 'content') that needs to be disabled when the dialog shows (binding to IsShown). When you click some button in the dialog the associated command is called that simply calls the associated action that was passed in the constructor of the viewmodel.
This way I would be able to call Show() and Hide() of the dialog on the dialog viewmodel from inside the Customer viewmodel and alter the dialog viewmodel as needed.
It would give me only one dialog at a time but that is fine.
I also think that the dialog viewmodel would remain unittestable, since the unittests would cover the calling of the commands that ought to be created after it being created with Actions in the constructor. There would be a few lines of codebehind for the dialog view, but very little and pretty dumb (setters getters, with almost no code).
What concerns me is:
Is this ok?
Are there any problems I could get into?
Does this break some MVVM principles?
Thanks a lot!
EDIT: I posted my complete solution so you can have a better look. Any architectural comments welcome. If you see some syntax that can be corrected the post is flagged as community wiki.
Source: (StackOverflow)
I have a user control, call it UserControl, that has a grid with the following column definitions:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="B"/>
<ColumnDefinition Width="*" SharedSizeGroup="C"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="D"/>
<ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="E"/>
<ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="F"/>
<ColumnDefinition Width="110" SharedSizeGroup="G"/>
<ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="H"/>
<ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="I"/>
<ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="J"/>
<ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="K"/>
<ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="L"/>
</Grid.ColumnDefinitions>
I also have MainWindow, which contains a grid itself, with the following property defined on the grid:
Grid.IsSharedSizeScope="True"
Now, I added a couple of UserControls to the grid in MainWindow (each to a separate row). My goal is to have each of the column widths of the different UserControls to remain in sync. Everything works fine when using SharedSizeGroup except for one thing. It seems that any column with a Width of * does not behave as it should. It looks like the * column widths are set as if they were Auto instead.
Are there any limitations/issues with SharedSizeGroup and * sizing? This seems like the best way to keep the column widths in sync but I can't seem to fix this.
Thanks.
Source: (StackOverflow)
I have a Window with my user control and I would like to make usercontrol width equals window width. How to do that?
The user control is a horizontal menu and contains a grid with three columns:
<ColumnDefinition Name="LeftSideMenu" Width="433"/>
<ColumnDefinition Name="Middle" Width="*"/>
<ColumnDefinition Name="RightSideMenu" Width="90"/>
That is the reason I want the window width, to stretch the user control to 100% width, with the second column relative.
EDIT:
I am using a grid, there is the code for Window:
<Window x:Class="TCI.Indexer.UI.Operacao"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tci="clr-namespace:TCI.Indexer.UI.Controles"
Title=" " MinHeight="550" MinWidth="675" Loaded="Load" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized" Focusable="True"
x:Name="windowOperacao">
<Canvas x:Name="canv">
<Grid>
<tci:Status x:Name="ucStatus"/> <!-- the control which I want to stretch in width -->
</Grid>
</Canvas>
</Window>
Source: (StackOverflow)
I am creating a WPF form. One of the requirements is that it have a sector-based layout so that a control can be explicitly placed in one of the sectors/cells.
I have created a tic-tac-toe example below to convey my problem:
There are two types and one base type:
public class XMoveViewModel : MoveViewModel
{
}
public class OMoveViewModel : MoveViewModel
{
}
public class MoveViewModel
{
public int Row { get; set; }
public int Column { get; set; }
}
The DataContext of the form is set to an instance of:
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
Moves = new ObservableCollection<MoveViewModel>()
{
new XMoveViewModel() { Row = 0, Column = 0 },
new OMoveViewModel() { Row = 1, Column = 0 },
new XMoveViewModel() { Row = 1, Column = 1 },
new OMoveViewModel() { Row = 0, Column = 2 },
new XMoveViewModel() { Row = 2, Column = 2}
};
}
public ObservableCollection<MoveViewModel> Moves
{
get;
set;
}
}
And finally, the XAML looks like this:
<Window.Resources>
<DataTemplate DataType="{x:Type vm:XMoveViewModel}">
<Image Source="XMove.png" Grid.Row="{Binding Path=Row}" Grid.Column="{Binding Path=Column}" Stretch="None" />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:OMoveViewModel}">
<Image Source="OMove.png" Grid.Row="{Binding Path=Row}" Grid.Column="{Binding Path=Column}" Stretch="None" />
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding Path=Moves}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
What was not so obvious to me when I started was that the ItemsControl element actually wraps each item in a container, so my Grid.Row and Grid.Column bindings are ignored since the images are not directly contained within the grid. Thus, all of the images are placed in the default Row and Column (0, 0).
What is happening:

The desired result:

So, my question is this: how can I achieve the dynamic placement of my controls in a grid? I would prefer a XAML/Data Binding/MVVM-friendly solution.
Thanks.
I have put the final code here:
http://www.centrolutions.com/downloads/TicTacToe.zip
Source: (StackOverflow)