Silverlight TextBlock TextTrimming inside ContentControl disappears - silverlight

I'm displaying a series of messages (like emails) on a Grid:
<layout:TransitioningContentControl Name="tccCmdMessage" Margin="0,4">
<layout:TransitioningContentControl.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" FontWeight="SemiBold" />
<TextBlock Name="tbCmdMessage" Text="{Binding Message}" TextTrimming="WordEllipsis" />
</StackPanel>
</DataTemplate>
</layout:TransitioningContentControl.ContentTemplate>
</layout:TransitioningContentControl>
However, the tbCmdMessage never displays. If I remove the TextTrimming (or change it to None) it works. Alternatively if I don't use a ContentControl parent it also works.
Any ideas?

Take a look at this link: http://social.msdn.microsoft.com/Forums/eu/wpf/thread/30fd3279-7bc8-424f-9ee6-41b9f9589a1a.
I suppose explicitly specifying the Width (or MaxWidth) of the StackPanel can make the texts trimmed. You can also try to use another type of container, like Grid.
Other links with similar issue described:
Silverlight text trimming and wrapping issue
TextTrimming not working
http://forums.silverlight.net/t/58227.aspx/1

Related

WPF TextBox in DataTemplate of ToggleButton does not show text if in toolbar flyout

If I put the Column where the toolbar is hosted to be very big (800) then all the text is visible:
but if I put a smaller column this happens:
But I cannot understand why:
<DataTemplate x:Key="IconFilterButton">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource LargeIconStyle}"
Text="{Binding}" />
<TextBlock
Margin="6,0,0,0"
VerticalAlignment="Center"
DataContext="{Binding}"
Style="{StaticResource BodyTextStyle}"
Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Tag}" />
</StackPanel>
</DataTemplate>
and here the definition
<ToggleButton
x:Name="DFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1d"
/>
<ToggleButton
x:Name="WFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1w"
/>
Even worst if I click on the button once they are out:
and then the text is visible but is wrong as the TextBlock is not considered in the object size:
The WPF ToolBar control uses a custom panel for the overflow Popup. In many styles, the ToolBarOverFlowPanel has a property WrapWidth set to a static value like 200. This determines how many items can be displayed before it wraps to another row in the popup.
I've created custom styling for this control and have found that the ToolBarOverFlowPanel used internally is buggy. That's probably the source of your problem.
You can re-template the ToolBar and wire-up a different value for WrapWidth to try to fix the issue, but my guess is that you'll still run into layout problems.
Otherwise, you might consider making your own replacement control.

Binding to DevExpress GridControl TotalSummary

I have a basic newbie binding question, which isn't necessarily directly related to the control used. Anyway, here's the thing: I have a DXGrid with a TotalSummary defined, which counts the rows of the grid.
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem x:Name="grdCompleteCount" FieldName="ar_id" SummaryType="Count"/>
</dxg:GridControl.TotalSummary>
Now I'd like to display the count not at the bottom of the grid as it is done automatically, but would like to bind it to another element, say, a textblock. Something like this:
<TextBlock x:Name="statusBarGridCount"
Text="{Binding ElementName=grdCompleteCount, Path=Value}"
TextAlignment="Right"
Width="190" />
But this approach doesn't work as I'm not sure how to get to the value I'm looking for. What's wrong with the binding?
Ok, got it already, don't worry... :) Works that way:
<StatusBarItem Grid.Column="2" BorderThickness="1" Margin="1">
<TextBlock x:Name="statusBarGridCount"
Text="{Binding ElementName=grdList, Path=VisibleRowCount}"
TextAlignment="Right"
/>
</StatusBarItem>

Is it possible to bind to a control's property from a datatemplate?

Ok, sounds odd, and there's likely a better way, but I haven't seen it yet.
What I'm trying to do is restyle a ListPicker under Windows Phone 7.
What I need is to
get rid of the header (that's easy, just define a null ListPicker.HeaderTemplate).
Force the picker to always go to full mode when clicked (again, easy, just set the ItemCountThreshold to 1).
Restyle the itemtemplate used when in FullMode (again, easy, just define a FullModeItemTemplate)
Incorporate the ListPicker's "HEADER" property value into the ItemTemplate (since only one item will ever show, i need the header text "embedded" within the one item).
It's that number 4 that I can't seem to get.
I've defined a listpicker like so (i'm directly defining the templates inline instead of in resources for now, just to keep things simple).
<phonekit:ListPicker Header="Header Text" x:Name="ListOfSounds"
SelectedItem="{Binding Path=DepartureChime, Mode=TwoWay, Converter={StaticResource EnumDescriptionToStringConverter}}"
ItemCountThreshold="1">
<phonekit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent">
<TextBlock Text="{TemplateBinding Header}" />
<TextBlock Text="{Binding}" />
<TextBlock Text=">" />
</StackPanel>
</DataTemplate>
</phonekit:ListPicker.ItemTemplate>
Ignoring all the obvious formatting bits for now, the problem I'm having is that I can't use {TemplateBinding Header} from within a datatemplate. I've used it from a ControlTemplate no problem.
The result of this ItemTemplate should be an item displayed such as
{TextOfHeader}{Content of selected Item}>
I'm just not sure how to go about getting at a property of the templated control (the listpicker in this case).
Any ideas?
Take advantages of RelativeSource:
<TextBlock Text="{Binding Path=Header, RelativeSource={RelativeSource AncestorType={x:Type phonekit:ListPicker}}}" />

WPF: Expand the validation rectangle

This is my current XAML.
<StackPanel Orientation="Horizontal" Grid.Column="3" Grid.Row="1">
<Label Content="Allocated:" FontSize="14"/>
<Label Content="{Binding AllocatedUnits, Mode=OneWay, ValidatesOnDataErrors=True}" ContentStringFormat="N0" FontSize="14"/>
</StackPanel>
How would I change this so that the red validation rectangle is around the whole text instead of just the number. (I will accept throwing away the stack panel entirely and doing something else.
A string-formatted binding would probably do the trick in this case, but that wasn't available in .NET 3.0 (in case you're still using that version!). If you can use it, you'd only need a single label control (so you can ditch both the other label and the stackpanel, and your validation border will wrap all the text in the remaining label).
EDIT: as per Jonathan's comment, it seems you need two attributes to do this on a content control...
Use something like this for your binding:
Content="{Binding AllocatedUnits, ValidatesOnDataErrors=true}" ContentStringFormat="Allocated: {0}"
MSDN documentation is here.

How does inheritance of FontSize in silverlight tree work?

If I have a ChildWindow in Silverlight I can apply the FontSizeProperty and it is inherited by child items.
<controls:ChildWindow FontSize="14">
<StackPanel>
<TextBlock Content="Hello">
<TextBlock Content="World">
</StackPanel>
</controls:ChildWindow>
Now that's fine if you want the whole page to have the same font size, but I want to do something like this and have inheritance in smaller blocks:
<controls:ChildWindow>
<StackPanel FontSize="14">
<TextBlock Content="Hello">
<TextBlock Content="World">
</StackPanel>
<StackPanel FontSize="10">
<TextBlock Content="Hello">
<TextBlock Content="World">
</StackPanel>
</controls:ChildWindow>
This doesn't compile. Is there any way i can achieve this pattern in Silverlight without having to define a style for StackPanel (I think that would work).
Are there any other containers that let me set FontSize for its descendants - or can I write one that would?
I want to easily set fontsize to be larger for certain StackPanels. I don't want to resort to styles because its very specialized and I won't need to reuse the style elsewhere.
Whats the best way to do this?
You can wrap each StackPanel in a ContentControl, which does implement FontSize.

Resources