I'd like to be able to click a textblock and have it run a Command. Is this possible? (if not do I just somehow make a tranparent button over it or something?)
The command is the action to be executed. The command source is the object which invokes the command. The command target is the object that the command is being executed on. The command binding is the object which maps the command logic to the command.
TextBlock is not editable.
Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.
You can use a InputBinding.
<TextBlock Text="Hello"> <TextBlock.InputBindings> <MouseBinding Command="" MouseAction="LeftClick" /> </TextBlock.InputBindings> </TextBlock>
Edit: Hyperlink is probably worth a mention too.
<TextBlock><Hyperlink Command="" TextDecorations="None" Foreground="Black">Hello</Hyperlink></TextBlock>
You do not make a transparent button over it, you put the TextBlock into it:
<Button> <Button.Template> <ControlTemplate TargetType="Button"> <ContentPresenter /> </ControlTemplate> </Button.Template> <TextBlock Text="Lorem Ipsum"/> </Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With