I have a comboBox, user controls and a button. SelectionChanged event is not firing in my UI App but when I copy the same combobox code in a different WPF app, selectionChanged event is firing. I don't understand why event is not triggered just here.
<Window x:Class="ExecutionInformation.TesterApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExecutionInformation.TesterApp.UserControls"
mc:Ignorable="d"
Title="MainWindow" Height="Auto" Width="800">
<ScrollViewer>
<Grid>
<StackPanel>
<Label Content="Execution Information service" Margin="20,10,20,10"
HorizontalAlignment="Center" FontSize="15" FontFamily="Bold"/>
</StackPanel>
<StackPanel Margin="20">
<!--<ComboBox Name="CmbAPIList" ItemsSource="{StaticResource ExecInfoServiceApis}"
DisplayMemberPath ="ValueString"
SelectedValuePath="ValueString" Margin="100,20,100,0"
SelectedValue="{Binding ColorString}" SelectionChanged="CmbAPIList_SelectionChanged"/>-->
<ComboBox Name="CmbAPIList"
SelectionChanged="CmbAPIList_SelectionChanged">
<ComboBoxItem>ApproveTestStartAsync</ComboBoxItem>
<ComboBoxItem>CompleteTestAsync</ComboBoxItem>
<ComboBoxItem>GetPartAsync</ComboBoxItem>
<ComboBoxItem>GetAssemblyAsync</ComboBoxItem>
<ComboBoxItem>PutAssemblyAttributesAsync</ComboBoxItem>
</ComboBox>
<local:ApproveTestStartUC x:Name="approveTestStartUC" Visibility="Collapsed" Margin="20,10,20,10" Background="Cyan" />
<local:CompleteTestUC x:Name="completeTestUC" Visibility="Collapsed" Margin="20,10,20,10" />
<local:GetPartUC x:Name="getPartUC" Visibility="Collapsed" Margin="20,10,20,10" />
<local:GetAssembly x:Name="getAssemblyUC" Visibility="Collapsed" Margin="20,10,20,10" />
<local:PutAssemblyAttributesUC x:Name="putAssemblyUC" Visibility="Collapsed" Margin="20,10,20,10"/>
<WrapPanel Margin="15" HorizontalAlignment="Center">
<Button Name="btnShowResults" Click="btnShowResults_Click" Visibility="Collapsed" Width="100">Show Results</Button>
</WrapPanel>
<Border BorderThickness="1" BorderBrush="LightGreen">
<TextBlock Name="TxtResults" Visibility="Collapsed"></TextBlock>
</Border>
</StackPanel>
</Grid>
</ScrollViewer>
Commented ComboBox code in the above code works without any issues.
Thanks
Related
I have 5 borders inside a stackpanel and each border has a width as Window width/5. When I am maximizing the window then each border width should get resize according to window width/5.
I have tried with converter but it does' not work as how converter will come to know window has resized.
<Window x:Class="ItemPanelTemplateTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Horizontal">
<Border Height="20" Background="Red" Width="105" />
<Border Height="20" Background="Green" Width="105" />
<Border Height="20" Background="Yellow" Width="105" />
<Border Height="20" Background="Blue" Width="105" />
<Border Height="20" Background="Orange" Width="105" />
</StackPanel>
</Window>
I don't want to write anything on codebehind as I am using MVVM.
Use different container than StackPanel. The best candidates here are Grid and UniformGrid, but since the latter requires less typing, here it is:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<UniformGrid Height="20" Rows="1">
<Border Background="Red" />
<Border Background="Green" />
<Border Background="Yellow" />
<Border Background="Blue" />
<Border Background="Orange" />
</UniformGrid>
</Window>
The grid will resize automatically with the window and then resize its contents uniformly.
I have a WPF UserControl with a textbox. Here's how the textbox and it's parent control are defined:
<DockPanel Margin="10,20,10,10" FocusManager.FocusedElement="{Binding ElementName=uxJobNumber}" >
<TextBox x:Name="uxJobNumber" Text="{Binding JobNumber, Mode=TwoWay, ValidatesOnDataErrors=True}" TextWrapping="Wrap" FontSize="48" BorderBrush="Black" BorderThickness="1" Margin="10"/>
</DockPanel>
With the FocusManager.FocusedElement set, I can see a cursor bar present within the textbox. However, the cursor bar is not blinking, and does not allow the user to immediately start typing.
Without the FocusManager.FocusedElement set, when the application starts there is no cursor bar within the text box at all.
Here's the complete XAML
<UserControl x:Class=""
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:.Modules.Converters"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
mc:Ignorable="d">
<UserControl.Resources>
<converters:VisibilityConverter x:Key="Visibility" />
</UserControl.Resources>
<Canvas Width="1024" Height="768" >
<Border Style="{DynamicResource GroupBox}" Canvas.Left="36.261" Canvas.Top="32.131" Width="426.936">
<StackPanel>
<Border>
<TextBlock Text="STEP 1"/>
</Border>
<TextBlock Text="Enter the five (5) digit Job Number and click Verify." />
<Path/>
<DockPanel Margin="10,20,10,10" FocusManager.FocusedElement="{Binding ElementName=uxJobNumber}" >
<Button Content="Verify" Width="125" Height="65" HorizontalAlignment="Right" Command="{Binding SearchJobCommand}" Style="{DynamicResource RedButton}" Margin="0" DockPanel.Dock="Right" IsDefault="True"/>
<TextBox Text="{Binding JobNumber, Mode=TwoWay, ValidatesOnDataErrors=True}" TextWrapping="Wrap" FontSize="48" BorderBrush="Black" BorderThickness="1" x:Name="uxJobNumber" Margin="10" KeyboardNavigation.TabIndex="0" />
</DockPanel>
</StackPanel>
</Border>
<TextBlock Text="{Binding Error}" Visibility="{Binding HasError, Converter={StaticResource Visibility}}" Canvas.Left="48" Canvas.Top="288" FontSize="16" Width="403" Foreground="Red" />
</Canvas>
We finally resorted to using the Focus() method in the code behind when the form is done loading.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
uxJobNumber.Focus();
}
Using your code I get this to work; blinking and all.
i am learning WPF here is my XAML.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
Height="300"
Width="634">
<StackPanel>
<Button Height="35"
Width="89"
Name="p1">Hello</Button>
<Border CornerRadius="5"
BorderThickness="1"
BorderBrush="Black"
Height="35"
Width="254"
Margin="91,192,150,79">
<TextBox HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Height="35"
Width="250"
Name="txtContents" />
</Border>
<Button Height="23"
Name="button1"
Width="75">Button</Button>
</StackPanel>
button textbox is showing but the problem is I am not being able to drag the control to another location. how to fix it. please help. thanks
If you mean you can't drag the Button controls to different locations, it's because they're contained within a StackPanel - stacking them one on top of each other.
If you change that StackPanel to be a Grid, you'd have the ability to drag it around in a canvas-like manner.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
Height="300"
Width="634">
<Grid>
<Button Height="35"
Width="89"
Name="p1">Hello</Button>
<Border CornerRadius="5"
BorderThickness="1"
BorderBrush="Black"
Height="35"
Width="254"
Margin="91,192,150,79">
<TextBox HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Height="35"
Width="250"
Name="txtContents" />
</Border>
<Button Height="23"
Name="button1"
Width="75">Button</Button>
</Grid>
This question may shed some light on where to use Grids and StackPanels.
If by "able to drag the control to another location" you are talking about repositioning the control using Expression Blend or the Visual Studio Designer you need to change the StackPanel to a Grid
So it would become-
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
Height="300"
Width="634">
<Grid>
<Button Height="35"
Width="89"
Name="p1">Hello</Button>
<Border CornerRadius="5"
BorderThickness="1"
BorderBrush="Black"
Height="35"
Width="254"
Margin="91,192,150,79">
<TextBox HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Height="35"
Width="250"
Name="txtContents" />
</Border>
<Button Height="23"
Name="button1"
Width="75">Button</Button>
</Grid>
I have simple ItemsControl with custom datatemplate, template contains only textblock with border. All items should be displayed vertically one after another, but some items have extra border.
How can I remove it?
I want to achieve something similar to enso launcher, it looks like
My implementation looks like this
here is my xaml code:
<Window x:Class="winmole.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
x:Name="hostWindow"
Height="Auto"
MinHeight="100"
MinWidth="100"
Width="Auto"
Padding="10"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Top="0"
Left="0"
SizeToContent="WidthAndHeight"
Topmost="True"
Loaded="Window_Loaded"
KeyUp="Window_KeyUp"
>
<Window.Resources>
<!--Simple data template for Items-->
<DataTemplate x:Key="itemsTemplate">
<Border Background="Black" Opacity="0.9" HorizontalAlignment="Left" CornerRadius="0,2,2,0">
<TextBlock Text="{Binding Path=Title}"
TextWrapping="Wrap"
FontFamily="Georgia" FontSize="30"
Height="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
TextAlignment="Left" Padding="5" Margin="0" Foreground="Yellow"/>
</Border>
</DataTemplate>
</Window.Resources>
<DockPanel>
<ItemsControl DockPanel.Dock="Bottom" Name="itcPrompt"
ItemsSource="{Binding ElementName=hostWindow, Path=DataItems}"
ItemTemplate="{StaticResource itemsTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
If I understand your question correctly: Try to set SnapsToDevicePixels="True" on the Border
<Border SnapsToDevicePixels="True" Background="Black" Opacity="0.9" ...
I have a really simple WPF UserControl:
<UserControl x:Class="dr.SitecoreCompare.WPF.ConnectionEntry"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="connEntry"
BorderBrush="Navy" BorderThickness="1" Margin="5,0,0,5" >
<StackPanel Margin="0,10,0,0" >
<Label FontWeight="ExtraBold" Content="{Binding ElementName=connEntry, Path=Title}"></Label>
<Label Margin="0,5,0,0">Server:</Label>
<TextBox x:Name="txtServer" TabIndex="1" Text="{Binding Path=ServerName}" ></TextBox>
<Label>Database:</Label>
<TextBox x:Name="txtDatabase" TabIndex="2" Text="{Binding Path=DatabaseName}"></TextBox>
</StackPanel>
This is used twice in the same window. Now, I can select the first TextBox on both th instances of my UserControl, but the second ("txtDatabase") textbox cannot be selected, neither by tabbing or clicking. Why is this ? Am I missing something with regards to creating WPF usercontrols ?
EDIT:
DatabaseName is not readonly, it is a simple property. The XAML for the window the usercontrol is placed on looks like this:
<Window x:Class="dr.SitecoreCompare.WPF.ProjectDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:dr.SitecoreCompare.WPF"
Title="Choose project" Height="280" Width="500"
WindowStartupLocation="CenterOwner" WindowStyle="SingleBorderWindow" HorizontalAlignment="Center" ShowInTaskbar="False" ShowActivated="True" ResizeMode="NoResize" VerticalContentAlignment="Top" VerticalAlignment="Center">
<StackPanel>
<Label>Choose databases</Label>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<c:ConnectionEntry Grid.Column="0" x:Name="connMaster" Title="Master:" Padding="5" />
<c:ConnectionEntry Grid.Column="1" x:Name="connSlave" Title="Slave:" Padding="5" />
</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0" >
<Button x:Name="btnCancel" Click="btnCancel_Click">Cancel</Button>
<Button x:Name="btnOK" Click="btnOK_Click">OK</Button>
</StackPanel>
</StackPanel>
</Window>
Try Mode=TwoWay in your binding. I've seen this where the initialization sets the value and the control can not set the the value.
<TextBox x:Name="txtDatabase" TabIndex="2" Text="{Binding Path=DatabaseName, Mode=TwoWay}"></TextBox>
This works in XamlPad, so I think there is something outside the code you posted that is causing the problem. Is DatabaseName readonly?