I have used the ViewBox Silverlight Toolkit control to bind to, however Silverlight 4 add this to the Core, however it no longer has a specific "Content" property to bind to - how to I bind Content to the new ViewBox?
For example I want to be able to do this (not valid syntax):
<ViewBox Content="{Binding Path=Canvas}"/>
Where the Content of the the Viewbox is a Canvas which can itself be many things.
If I put a ContentPresenter inside the ViewBox and Bind to this it works - putting this as the answer as it may be useful so others as it solved the issue.
<ContentPresenter Content="{Binding Path=Canvas}"/>
Related
If I try displaying an instance of Microsoft.Phone.Maps.Control.Map in a ContentControl like this:
<ContentControl><maps:Map/></ContentControl>
the map will not display. However, if I do not wrap it with a ContentControl, map displays just fine.
I need to wrap it in a container, preferably one that will allow binding to the control. Hoping to do this:
<ContentControl Content="{Binding MainMapView, Mode=OneTime}"/>
Ideas anyone?
Strangely enough using a Border control works fine as follows:
<Border Name="MapContentControl" Child="{Binding MainMapView, Mode=OneTime}"></Border>
I am trying to override the default template for TabControl in Silverlight. Instead of having the tabs wrap around when they are full, I want to make it so the user can scroll through them, similar to a ListBox. However, Silverlight just ignores everything I put in "ItemsPanelTemplate" and renders the default. Here is the relevant code:
<swc:TabControl Grid.Row="0" Grid.Column="1" Name="Tabs">
<swc:TabControl.ItemsPanel>
<ItemsPanelTemplate>
<ScrollViewer>
<StackPanel Orientation="Horizontal" />
</ScrollViewer>
</ItemsPanelTemplate>
</swc:TabControl.ItemsPanel>
Even if I just put in a regular StackPanel, it still does nothing at all. I am using the Silverlight Toolkit for the tabs, so everything I find online is just for regular WPF and does not work for Silverlight. Thank you all very much for your advice.
The ItemsPanel needs to have a Panel in it as the root element. You have a ScrollViewer. If you want to add a ScrollViewer, you'd have to create a custom ControlTemplate that wraps the ItemsPresenter with a ScrollViewer. The ItemsPresenter will be where the ItemsPanel is shown.
You should be able to get the default Style and ControlTemplate from the Silverlight Toolkit source and tweak it to your needs. Then include your modified version in your application resources or apply it explicitly to individual TabControls.
New to Silverlight. I'm working on a chat application where new chat messages are added to the bottom of a list. I had a working version that used as StackPanel inside a ScrollViewer and then in some code behind used StackPanel.Children.Add().
I'm trying to convert this to a View-ViewModel approach, and I can't figure out how to bind the Children of the StackPanel to any collection property. I've tried this:
<ScrollViewer Name="scrollMessages" Grid.Row="2" Margin="0,0,0,0" VerticalScrollBarVisibility="Visible">
<StackPanel x:Name="pnlMessages" Orientation="Vertical" Children="{Binding Path=ExampleTBs}" />
</ScrollViewer>
where ExampleTBs is a collection of TextBlocks created in code. This fails XAML parsing, the Children property isn't bindable in this way.
Is the approach of binding to the StackPanel itself fixable? Should I be using a different container type? I saw another question where the guy created the entire StackPanel in code and then used a ContentPresenter...
Bottom line, I'd like to find a way to databind my view to a viewmodel using something like a StackPanel as a container where successive items will be added to the container over time. Best approach?
Use a ListBox (or any other ItemsControl) and bind the ItemsSource property to an ObservableCollection in your ViewModel.
Do you need to use a StackPanel? If you use an ItemsControl instead, this still presents each chat message in a vertical list, and also allows for binding of the data.
What I'd like is a control that functions just like the tab control but instead of having the tabs along the top, the items would be displayed in a list box along the side. I imagine it's possible but haven't found any examples, I'm hoping there's someone here that's done something like this.
WPF controls are designed to enable exactly what you want. To reuse control functionality while completely replacing the visual representation. You will have to create your own ControlTemplate for the TabControl. You can find a TabControl ControlTemplate Example on MSDN. You will also have to study the Control Authoring Overview on MSDN.
I actually find the Silverlight 3 documentation somewhat easier to digest, and even though there are some differences when it comes to control styling the fundamental concepts are still the same. You can read Customizing the Appearance of an Existing Control by Using a ControlTemplate on MSDN to learn about control templates and then study TabControl Styles and Templates to discover what is required to create you own control template in Silverlight.
You can use Expression Blend to extract the the default TabControl template in WPF.
You don't need to use a TabControl at all. You could just bind your ListBox to a list of items, and put a ContentControl beside it, bound to the selected item :
<DockPanel>
<ListBox Name="listBox"
DockPanel.Dock="Left"
ItemsSource="{Binding Items}"
DisplayMemberPath="Name"/>
<ContentControl Content="{Binding SelectedItem, ElementName=listBox}"
ContentTemplate="{StaticResource theTemplate}"/>
</DockPanel>
I have a control bound to an Object and all is well but I want to turn it into a control template bound to different objects of a similar type. I would like to do this exclusively in xaml, if possible. Any good tutorials that outline the steps?
<TextBlock Text="{Binding Source={StaticResource BorderControl}, Path=ControlName}"/>
EDIT: With a little more experience, it turns out what I need is the ability to Set the Binding source based on a property of the control. i.e.
<TextBlock Text="{Binding Source={StaticResource {TemplateBinding Tag}}, Path=ControlName}"/>
The control exists within a ControlTemplate but works correctly if I bind it directly to the data -- if that makes a difference. I don't know if this is possible or if it's the correct approach. Any thoughts welcome!
EDIT:
This doesn't work either.
<TextBlock Text="{Binding Source={TemplateBinding Tag}, Path=ControlName}"/>
I think you want ContentPresenter here (http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter.aspx) - think of it as one line of an ItemsControl, it's got a content and a reference to a template that will represent that content.