Imagine I have a simple DataField in my Silverlight app. something like this:
<toolkit:DataField Label="This is my test label:">
<TextBox ... etc... />
</toolkit:DataField>
Is it possible to style the label in above example so that only the word "test" is bold?
you can use Run tag inside a textblock tag like this :
<toolkit:DataField >
<toolkit:DataField.Label>
<TextBlock >This is my <Run FontWeight="Bold">test</Run>label</TextBlock>
</toolkit:DataField.Label>
<TextBox ... etc... />
</toolkit:DataField>
i hope that it fixe your pb.
Related
When I have TextBlock. Run Text = "(" Run Text={Binding IncomeLoss} Run Text=")" in a Page it comes out looking ok,
but when I have the same thing inside a ControlTemplate that I apply to a class that derives from Control, there is extra space after each character like "( 100 ) ".
I read that ControlTemplate is a barrier to style inheritance, but how do I guess what exactly style parameter is the one missing that is usually inherited by the Textblock on a Page?
Make sure that you have put all Run elements on the same line in the ControlTemplate.
There is a difference in output between this:
<TextBlock><Run Text = "(" /><Run Text="{Binding IncomeLoss}"/><Run Text=")"/></TextBlock>
...and this:
<TextBlock>
<Run Text = "(" />
<Run Text="{Binding IncomeLoss}"/>
<Run Text=")"/>
</TextBlock>
If this doesn't work you should provide a minimal, complete, and verifiable example of your issue: https://stackoverflow.com/help/mcve
I would like to be able to change the weight of text (e.g. change from Normal to Bold and back again) within the Text property string of a TextBlock (presumably using some control character set). Is this even possible?
TextBLock.Text creates a single Run, you set custom Inlines instead:
<TextBlock>
Text with <Bold>bold</Bold> within.
<TextBlock>
Obviously it no longer uses the Text property.
Are you talking about something like this?
<TextBlock>
<Run Text="Hey it's Normal Text"/>
<Run Text="Hey it's Bold Text" FontWeight="Bold"/>
<Run Text="Hey it's Colored Text" Foreground="Green"/>
</TextBlock>
I want to display a dialog form for new and edit actions... However title, buttons , and few other things should change.
I am wondering how i could implement this. Provide an enum value at constructor ? Like Mode.New or Mode.Edit ? Is there a way to avoid writing code like spNewButtons.Visibillity=Collapsed .. etc , and put it inside wpf ?
You can bind visibility with your mode property, and create a specific IValueConverter to convert the mode to a proper Visibility value. ie:
<StakPanel Visibility={Binding Mode,Converter={StaticResource myProperConverter}}></StackPanel>
Usually my WPF dialogs are all ContentControls that get displayed in a Popup.
My code usually looks like this:
<Grid Name="RootPanel">
<!-- Other Content -->
<!-- Popup is always last so it gets displayed on top of other contnet -->
<local:PopupPanel
local:PopupPanel.PopupParent="{Binding ElementName=RootPanel}"
local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"
local:PopupPanel.PopupEnterKeyCommand="{Binding SaveCommand}"
local:PopupPanel.PopupEscapeKeyCommand="{Binding CancelCommand}">
<DockPanel>
<!-- Header -->
<Label DockPanel.Dock="Top" Content="{Binding PopupHeader}" />
<!-- Buttons -->
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save" Command="{Binding PopupSaveCommand}" />
<Button Content="Cancel" Command="{Binding PopupCancelCommand}" />
</StackPanel>
<!-- Actual content displayed is determined by DataTemplates -->
<ContentControl Content="{Binding PopupContent}" />
</DockPanel>
</local:PopupPanel>
</Grid>
I removed a lot of the styles to make this easier to read, but you can see the general idea of how it's put together. My ViewModel usually contains properties for IsPopupVisible, PopupContent, and PopupHeader, and commands for PopupSaveCommand and PopupCancelCommand
I use my own custom popup in most cases, although the same thing could be done with a WPF popup.
I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something allowing me to show a small number besides every one control.
Some text ³
I came with the idea to write a MarkupExtension, where I could write that number like this:
..
<TextBlock Text="Some Text" SomeExtension="3" />
..
and then to add it somehow to the template of the Control.
But I'm sure, you guys have better solution for this problem ;)
One way to go with it would be create a Attached Property. Upon setting it on a control, a custom Adorner would be added for that control showing specified number.
Use the tag property to provide the number you want and inside the custom template databind to the property
<TextBlock Text="Some Text" Tag="3" />
and inside the controltemplate
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}"/>
I have a WPF conundrum. I want some text to look like this:
Enter this preparer's info:
[ComboBox]
Alt+E is the access key that focuses the ComboBox, and when Alt is pressed, the E in the text should be underlined.
I can get the access key to work easily:
<Label Target="{Binding ElementName=PreparerComboBox}">
_Enter this preparer's info:</Label>
But then "preparer's" can't be bold because a Label doesn't support Runs (as far as I can tell).
I can do the bolding easily in a TextBlock:
<TextBlock>Enter this <Bold>preparer's</Bold> info:</TextBlock>
But there's no access key defined, so I tried adding my AccessText inside the TextBlock:
<Label Target="{Binding ElementName=PreparerComboBox}">
<TextBlock>
<AccessText>_Enter</AccessText> this <Bold>preparer's</Bold> info:
</TextBlock>
</Label>
But then the AccessText doesn't line up properly with the rest of the text in the TextBlock, and Margin doesn't seem to have any effect on it.
Example:
The best I've come up with so far is this monstrosity:
<Label Target="{Binding ElementName=PreparerComboBox}">
<WrapPanel>
<AccessText>_E</AccessText>
<TextBlock>nter this <Bold>preparer's</Bold> info:</TextBlock>
</WrapPanel>
</Label>
What am I missing here? Seems like there has to be an easier way.
Didn't change much but how about
<Label Target="{Binding ElementName=PreparerComboBox}">
<StackPanel Orientation="Horizontal">
<AccessText>_Enter</AccessText>
<TextBlock xml:space="preserve"> this <Bold>preparer's</Bold> info:</TextBlock>
</StackPanel>
</Label>