StackPanel in Button.Content inside DataTemplate shows as text - wpf

So I have an <ItemsControl> with <ItemsControl.ItemTemplate> defined as <DataTemplate><Button>...</Button></DataTemplate>.
This button has a StackPanel set as its content. But it shows as "System.Windows.Controls.StackPanel" string and not as actual visual content of the StackPanel.
Why and how to change that?

OK, I missed the fact that in a custom template used the content was rendered inside a <TextBlock/>.

Related

Why is my TabControl ignoring my ItemsPanelTemplate?

I've used the ItemsPanelTemplate on other controls such as the ListBox, so I figured doing the same thing for the TabControl would be simple.
Apparently, I'm missing something and the TabControl is completely ignoring what I place in the ItemsPanelTemplate.
I have xaml that looks kinda of like this:
<TabControl TabStripPlacement="Right" ItemsSource="{Binding Components}">
<TabControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</TabControl.ItemsPanel>
</TabControl>
I've tried replacing WrapPanel with UniformGrid to see if there was a difference and it behaves the same. I do have a ControlTemplate for TabItem, but I tried removing it and it made no difference so I don't think that's effecting my problem.
You're probably looking to overwrite the Template, not the ItemsPanel
You can overwrite TabControl.ItemTemplate (or TabItem.Template) to alter the appearance of the Tabs along the top, TabControl.ContentTemplate to alter the template used for the content of the Tab, or TabControl.Template to alter the overall template of the TabControl.
I wasn't even aware that TabControl's had an ItemsPanel. I've only ever used that with an ItemsControl, where the ItemsPanel affects what kind of control contains the items in the collection. If the TabControl has that property, I expect it's only because it inherited it from some base class

Using expression blend to define the template of an item in a listbox. What am I doing wrong?

I am new to expression blend and defining some templates to my items in a WP7 page.
I have a listbox and I want to use EB to define the template of my items, the value (the text that should go in the listboxitem) is stored in a ObservableCollection which is itemsource of my listbox.
I opened my project in expression blend. I opened the page, selected the listbox and right-clicked, then I chose ItemTemplate (in another try I chose ItemContainerStyle). a new page appeared and I added a textbox to my template.
When I ran the project, in both cases (using ItemTemplate and ItemContainerStyle), I got a list with "TextBox" written, which is logic because of textbox I added to the template.
I imagine I have to change the TextBox's Text property to define a binding. But how can I define that the value used is stored in the Listbox.ItemSource property?
Thanks!
Just found it!
<TextBlock TextWrapping="Wrap" Text="{Binding}" TextAlignment="Center" FontWeight="Bold"/>
Text={Binding} solved my problem :)

Set WPF TabControl to show the same Content for every tab

I'd like to use a TabControl where each tab shows the same view just with different parameters. Therefore I do not want to create a new content control for each tab but reuse the same control for all tabs (binding some properties of it to the SelectedItem property of the TabControl)
I tried to my contained control as resource and set the Content property of the tab items to it, but this resulted in an exception, because the same element cannot appear as content in to different parents.
Any ideas?
<TabControl>
<TabControl.ContentTemplate>
<DataTemplate>
your view
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
I found a solution in this question
TabControl's TabItems sharing same content... Do Not Want
(even if the poster wanted specifically the opposite behaviour :) ...)

Make a silverlight textblock act like a hyperlink

I'm pretty new to silverlight. I have a text block that is displayed inside a datagrid
(inside a DataGridTemplateColumn.CellTemplate template to be precise).
I'd like to dynamically make some of the textblocks into hyperlinks that open a new window.
Is there a way to do this - so far all I can come up with is using a hyperlink button and trying to style it to look like a text block.
Any help would be very much appreciated.
HyperlinkButton is a ContentControl so it can actually take some kind of pre-styled TextBlock (or other control) as it's content (instead of just using a simple string as Content).
<HyperlinkButton NavigateUri="http://myurl.com">
<TextBlock Text="My Link Text" Foreground="Black" />
</HyperlinkButton>
You would have to use a custom HyperlinkButton template if you wanted to style it to get rid of the default teal colored focus ring, etc. You could also set the IsEnabled property of the HyperlinkButton to false to prevent link behavior on any cells that weren't actually links if you are trying to set them up in some dynamic way.

WPF resizing TextBlock

I have a textblock in a grid in WPF.
I want the text to dynamically size (font) when resized. At the moment textboxes, comboboxes do this, but the the textblock stays the same. Is it possible?
Instead of trying to manually rig a TextBlock to do this, just edit the default template of a TextBox and remove the border and background, then in the style make it set the IsReadOnly flag. This way you get the textblock sizing, as well as copy-paste for free.
You can use a ViewBox for this.
eg:
<Viewbox Stretch="Uniform">
<TextBlock Text="Test" />
</Viewbox>
use expression blend for getting the default template of TextBox, then you can edit it as you required.

Resources