textblock

WPF TextBlock Negative Number In Red

扶醉桌前 提交于 2019-12-05 03:22:36
I am trying to figure out the best way to create a style/trigger to set foreground to Red, when value is < 0. what is the best way to do this? I'm assuming DataTrigger, but how can I check for negative value, do i have to create my own IValueConverter? Wonko the Sane If you are not using an MVVM model (where you may have a ForegroundColor property), then the easiest thing to do is to create a new IValueConverter, binding your background to your value. In MyWindow.xaml: <Window ... xmlns:local="clr-namespace:MyLocalNamespace"> <Window.Resources> <local:ValueToForegroundColorConverter x:Key=

Create DataGridTemplateColumn Through C# Code

假装没事ソ 提交于 2019-12-04 23:11:02
I have a dynamic Datagrid that I have created. I am creating each column for it through code behind. I am having troubles on a column that I want to be displayed at a textblock when not editing, but as a combobox while editing. I have an ObservableCollection of Transactions. Each Transaction has a type called "Account". Here is what I have so far: private DataGridTemplateColumn GetAccountColumn() { // Create The Column DataGridTemplateColumn accountColumn = new DataGridTemplateColumn(); accountColumn.Header = "Account"; Binding bind = new Binding("Account"); bind.Mode = BindingMode.TwoWay; //

Vertically aligning Labels and TextBlocks at Top in XAML

柔情痞子 提交于 2019-12-04 20:56:45
问题 How can I vertically align a Label and TextBlock at Top so that their first lines of text line up? <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Label Grid.Column="0" VerticalAlignment="Top">Some Label:</Label> <TextBlock Grid.Column="0" VerticalAlignment="Top">Some text<TextBlock> </Grid> The above code gives me this: Vertically misaligned Label and TextBlock

How to refer MaxWidth=“??” of TextBlock to Owner ActualWidth?

不羁的心 提交于 2019-12-04 20:51:34
How to refer MaxWidth="??" of TextBlock to stpMessage ActualWidth ? <StackPanel Name="stpMessage" Orientation="Horizontal" Margin="0,5,0,0"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <TextBlock Margin="0,0,0,0" Foreground="Blue" TextWrapping="Wrap">@ToUserName</TextBlock> <StackPanel Grid.Column="1"> <TextBlock Margin="5,0,0,0" Text="{Binding Path=Text}" MinHeight="20" MinWidth="200" HorizontalAlignment="Stretch" MaxWidth="1000" VerticalAlignment="Stretch" TextWrapping="WrapWithOverflow">START skf skdjf skdj

How to Change the SelectedItem Foreground Text of ListBox Item

自古美人都是妖i 提交于 2019-12-04 16:07:21
I have the following ListBox below. I am not sure how to change the Foreground of a selected item's textblock text when an item is selected, and then back to the original foreground color when an item is unselected (most likely occurring when another item in the ListBox is selected afterwards)? <ListBox Name="ListBox" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}" toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" > <ListBox.ItemsPanel> <ItemsPanelTemplate> <toolkit:WrapPanel ItemWidth="159" ItemHeight="Auto" /> </ItemsPanelTemplate> <

Current Date in Silverlight XAML TextBlock

让人想犯罪 __ 提交于 2019-12-04 10:55:24
问题 I am coming from Flex where you can do just about anything inside of curly braces. I am trying to get a TextBlock to display today's Date and Time without just coding it in C#. I have tried many different variations of the following with no luck. TextBlock Text="{Source=Date, Path=Now, StringFormat='dd/MM/yyyy'}" I know I could probably just set a property MyDate and bind to that but why can't I bind directly to the DateTime.Now property? 回答1: Binding in Silverlight requires a Source object

Default TextBlock style overriding button text color

廉价感情. 提交于 2019-12-04 10:13:34
My problem occurs with WPF in .NET 3.5 SP1 and can be described as follows: I have a default Style hitting all TextBlock elements in my UI. That is how it looks: <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextTrimming" Value="CharacterEllipsis"/> <Setter Property="Foreground" Value="Red"/> </Style> That works fine for all TextBlock s. In addition to that I have a Button style including a ControlTemplate that looks like this (shortened): <Style x:Key="MyButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Null}"> <Setter Property="Foreground" Value="Green"/> <Setter Property=

How would I databind a Paragraph to a TextBlock?

纵然是瞬间 提交于 2019-12-04 09:50:28
How would I take a Paragraph object and databind them to the TextBlock for use in a DataTemplate? A plain bind does nothing, just a ToString() of the Paragraph object. The InLines property would let me add a list of TextRun's that make up the Paragraph manually, but that can't be bound to and I could really do with a binding based solution. Edited question to focus on what I really need to do. Here's an example using a nested ItemsControl. Unfortunately, it will make one TextBlock per Inline instead of putting the whole Paragraph into one TextBlock: <Grid xmlns="http://schemas.microsoft.com

Give TextBlock Default Value if result returns null

时光总嘲笑我的痴心妄想 提交于 2019-12-04 07:38:33
问题 Hello I am trying to give a default value to a textblock if the results returned are null Here is what I am trying! All that returns is the String Format I set! <TextBlock x:Name="NameTxtBlock" Grid.Column="0" Margin="0,0,40,0" FontFamily="Segoe UI" FontSize="14" Text="{Binding Name, StringFormat='Item Name: {0}'}" Padding="2"> <TextBlock.Style> <Style TargetType="TextBlock" > <Style.Triggers> <DataTrigger Binding="{Binding ElementName=NameTxtBlock, Path=Text}" Value="{x:Null}"> <Setter

WP7 TextBlock inside a ListBox not wrapping text

只谈情不闲聊 提交于 2019-12-04 07:15:37
I have a ListBox which has StackPanel s holding a TextBlock and an Image horizontally, followed by a ContentPresenter . This is what the XAML looks like: <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox x:Name="MainListBox" Margin="12,0,12,0" SelectionChanged="MainListBox_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <toolkit:ContextMenuService.ContextMenu> <toolkit:ContextMenu x:Name="ContextMenu" Opened="ContextMenu_Opened"> <toolkit:MenuItem Header="edit" Tag="edit" Click="MenuItem_Click" /> <toolkit:MenuItem Header="delete" Tag="delete" Click=