Label Target="{Binding ElementName=UIName}" bug, or is it just me? - silverlight

I've been tring to get this example to work, but there seems to be a bug in the code Label Target code, in that when you click on the second label the focus is set to the DatePicker rather than the TextBox, regardless which label you click first, also when you have entered the date the second label still sets it focus to DatePicker.
<!-- Unbound Date of Birth field -->
<sdk:Label Content="Date of Birth" IsRequired="True" Margin="5" />
<StackPanel Orientation="Horizontal" Grid.Column="1">
<sdk:DatePicker Height="23" />
<sdk:DescriptionViewer Description="Please enter your date of birth."/>
</StackPanel>
<!-- ID Number field -->
<sdk:Label Grid.Row="1" Margin="5" Target="{Binding ElementName=tbIdNumber}" />
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
<TextBox x:Name="tbIdNumber" Height="23" Width="100"
Text="{Binding IdNumber, Mode=TwoWay,
ValidatesOnExceptions=True, NotifyOnValidationError=True}" />
<sdk:DescriptionViewer Target="{Binding ElementName=tbIdNumber}"/>
</StackPanel>
I found this example here on the MSDN link text. To me this seems to be a bug, or am I just losing it?
Apologies if this is a duplicate question... I have googled this and all the examples seem to be the same, in that the target element is not being focused to.

It seems a reasonable assumption that clicking the label ought to move the focus to the associated control. However the Label does not actually provide that function.

Related

Tabindex not working for materialDesign:TimePicker

<StackPanel Orientation="Vertical" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1">
<TextBlock Text="{x:Static meta:MetaCommon.Returned}" Style="{StaticResource SectionHeader}" Margin="0,0,0,10" />
<TextBlock Text="{x:Static meta:MetaCommon.Date}" Style="{StaticResource ContentHeader}" />
<DatePicker TabIndex="10" HorizontalAlignment="Left" MinWidth="200" Margin="0,0,0,10" />
<TextBlock Text="{x:Static meta:MetaCommon.Time}" Style="{StaticResource ContentHeader}" />
<materialDesign:TimePicker TabIndex="11" HorizontalAlignment="Left" Width="200" materialDesign:HintAssist.Hint="" Margin="0,0,0,0" />
</StackPanel>
So the TabIndex works properly for everything except TimePicker. It will just skip to the next TabIndex. I'd like it to tab to the TimePicker in the proper order.
I'm not sure what the issue is because I've tried various ways and it just doesn't follow the tab order I set. The only time it gets selected is if I keep "tabbing" through the controls it eventually gets selected.
I tried setting a TabIndex of both "0" and "1" and I tried setting TabStop to both "True" and "False" but nothing seems to work apart from continuous tabbing and hoping it gets selected.
I even tried setting it in the code behind to just to make sure.
As far as I can gather, it could be that, because it is a part of the Material Design XAML Toolkit, it doesn't support direct TabIndex like native controls.

Textbox Highlighting Always Starting at 0

This is really annoying.
I have basic textboxes which do not allow highlighting of single words/characters. Every time I try to select single words/characters, the highlight immediately jumps to the front of the box and highlights everything up to where I clicked.
<TextBox Name="txtTaskName" AutoWordSelection="False" Grid.Row="0" Grid.Column="2" Text="{Binding TaskName, Mode=TwoWay}" MaxWidth="300" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" TextWrapping="Wrap" VerticalContentAlignment="Center"></TextBox>
Suggestions?
Set AutoWordSelection="False" on your TextBox
<TextBox AutoWordSelection="False"/>

Silverlight 4: Dispatcher-error when using Calendar or DatePicker

I read so many good answers on this site, so I never had to ask something.
Now I have a problem I cant find a answer. I'm programming a Windows App für 7.1 and try to use a Calendar Control, I dont care that much if its Calendar or DatePicker.
But whenever I change the value there, I get the following error:
"This type of Collection does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
Since im quite beginner, I dont do anything fancy with Threads and I didnt find anything about this error in the web, so I guess, this must be a unique error at my environment.
Has anyone a idea, where this error can come from?
Thanks for your responses
Müller Matthias
You should use DatePicker from SDK namespace,
http://samples.msdn.microsoft.com/silverlight/samplebrowser/#/?sref=System.Windows.Controls.Calendar
I can also suggest Telerik's silverlight controls
http://demos.telerik.com/silverlight/
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="CalendarExample.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontFamily="Trebuchet MS" FontSize="11"
Width="600" Height="750">
<StackPanel x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal" Margin="5" >
<!-- A basic Calendar. -->
<TextBlock Width="100"
Text="Calendar with date ranges defined:" TextWrapping="Wrap" Margin="5" />
<sdk:Calendar x:Name="cal" />
<!-- A Calendar does not highlight today's date. -->
<TextBlock Width="100"
Text="Calendar that does not highlight today's date:" TextWrapping="Wrap" Margin="5"/>
<sdk:Calendar x:Name="cal2" Canvas.Left="270" Canvas.Top="100"
IsTodayHighlighted="false" />
</StackPanel>
<!-- Two DatePicker controls, one using the default Short date format -->
<!-- and the other using the Long date format. -->
<StackPanel Orientation="Horizontal" >
<TextBlock Width="200" Margin="5"
Text="DatePicker with Short date format and Calendar event handlers:" TextWrapping="Wrap" />
<sdk:DatePicker x:Name="dp1" Height="20" Width="200" />
</StackPanel>
<StackPanel Orientation="Horizontal" >
<TextBlock Width="200" Margin="5"
Text="DatePicker with Long date format and DateSelected event handler:" TextWrapping="Wrap" />
<sdk:DatePicker Height="20" x:Name="dp2" SelectedDateFormat="Long" Width="200"/>
</StackPanel>
<!-- Output TextBlock -->
<TextBlock x:Name="text1" HorizontalAlignment="Left" Height="40" Width="350" Margin="5" />
<!-- A Calendar to demonstrate multiple selection. -->
<StackPanel Orientation="Horizontal" >
<TextBlock Width="200" Margin="5"
Text="Calendar with multiple selections and blackout dates:" TextWrapping="Wrap" />
<sdk:Calendar x:Name="cal3" />
</StackPanel>
</StackPanel>

Calendar control width is too large at initialization of usercontrol

I have used calendar control and its display mode is year when my user control is loads then calender width s too large and doesn't appear when width is set .but when is select any month then width is set as it should
i m not getting what is the issue behind it
can anyone help me quickly???
Here is my code and what ever selected month will appear in textbox's text property and on click event of button my calendar control is set to visible
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="HorizontalHorizontalAlignment="Left "Margin="4">
<Label Content="Month: " HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="15" FontWeight="DemiBold" Margin="4"/>
<TextBox Height="23" HorizontalAlignment="Stretch" Name="SelectedMonthTextBox" VerticalAlignment="Top" Width="130" Margin="4" LostFocus="SelectedMonthTextBox_LostFocus" SelectionBrush="#FF767879"/>
<Button Content=".." Height="20" Width="20" Margin="4" Name="button" Click="button_Click" />
</StackPanel>
<Calendar Grid.Row="1" Grid.Column="0" Margin="50,-8" Panel.ZIndex="100" Name="calendar1" DisplayModeChanged="calendar1_DisplayModeChanged" DisplayDateChanged="calendar1_DisplayDateChanged" HorizontalAlignment="Left" DisplayMode="Year" Style="{StaticResource CalendarStyle}" Focusable="False" HorizontalContentAlignment="Left" VerticalAlignment="Top" />
i took a look your code and from information you provided so far, there is no any change a you describe. I believe that you should check following:
What happens in calendar1_DisplayModeChanged
How defined your style: StaticResource CalendarStyle
If it possible please post them here. I will try to help as soon as possible :)

WPF: Is there a sort of XAML tag that behaves like the HTML span element?

Coming from ASP.NET, this WPF stuff is just confusing. All I want to do is put a red asterisk by a label to indicate a required field. Playing around with stuff, I found that this actually does the trick:
<TextBlock Grid.Row="6" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
<Label Foreground="Red" Content="*" /><Label Content="Heavy Weight" />
</TextBlock>
Being that I just came up with this, I am not convinced it's the academic route a seasoned WPF developer would take. Additionally, this markup puts a huge amount of white space in between the asterisk and the label. In HTML, a span element would just render right beside its next sibling element. FYI, I tried putting a label within a label, but VS2010 kept barking about "The property 'content' is set more than once".
Any ideas?
Something like this would be more appropriate:
<TextBlock Grid.Row="6" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
<Span Foreground="Red">*</Span>Heavy Weight
</TextBlock>
Here is an overview of what can go into a TextBlock's content, more specifically here.
one more way is
<TextBlock Grid.Row="6" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
<Run Foreground="Red" Text="*" />
<Run Text="Heavy Weight" />
</TextBlock>
btw
Damascus's solution adds more UI Elements.
with CodeNaked's solution, its difficult to databind the Text.
The explanation is that you actually put two elements one after the other. You need to put them into a container.
Just a sample code of a sentence with red asterisk I did recently:
<StackPanel Orientation="Horizontal" Margin="5" >
<TextBlock Text="Display name"/>
<TextBlock Text="*" Foreground="Red" FontWeight="Bold" />
<TextBlock Text=":"/>
</StackPanel>
There, everything is in a StackPanel, so property 'content' will actually be set once (if you don't specify a group panel such as this one, you'll have to add only one element)

Resources