I'm hoping to create a control that I call an "AutoCompleteListBox". If you've ever used hotmail to send an e-mail the way the to: address line works is what I wish to create. You have what looks like an input box and as you type you get a dropdown of matching objects. Once you select an object (contact) it is added into the input box as a rectangular object. Multiple objects can be added this way and the input box acts like a wrap panel. You can delete objects by backspacing them or clicking the x button on each.
My approach was to begin by subclassing ItemsControl. I've started to write its control template which is basically a wrap panel that I want to show the bound items + a text box. I don't know how to get both the bound items and the textbox to be in the same wrap panel. Here's what I have:
<Style TargetType="ctrl:AutoCompleteListBox">
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ctrl:AutoCompleteListBox">
<ScrollViewer x:Name="RootScrollViewer" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Padding="0" Background="{TemplateBinding Background}">
<toolkit:WrapPanel IsItemsHost="True">
<!--Items Bound To ItemSource Go Here-->
<TextBox x:Name="txtInput"/>
</toolkit:WrapPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I don't know how to express what I want. I know you can use an "ItemsPresenter" in the control template which does show the bound items but then how can I add my textbox into the same panel as the bound items?
I'd greatly appreciate any help. Is this the right way to even go about it? Thanks very much.
Subclassing the items control is a good start, but I think the controltemplate should be setup a bit different. The Silverlight toolkit contains an excellent autocomplete box that you can use for this exact purpose. Combine this with a separate items control and you should have something that can be styled to look exactly like the live mail "To" field.
<ControlTemplate>
<toolkit:WrapPanel>
<ItemsControl ItemsSource="{TemplateBinding Items}">
<ItemsControl.ItemsPanel>
<StackPanel Orientation="Horizontal"/>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<!-- Add data template for the previously added items here -->
</ItemsControl.ItemTemplate>
</ItemsControl>
<toolkit:AutoCompleteBox ItemsSource="{TemplateBinding AutoCompleteItems}" />
</toolkit:WrapPanel>
</ControlTemplate>
Related
I wants to create a form in a specified format where main window area will have some common links or buttons to all pages and the page area is where all the pages will be shown. Is this possible in wpf ?
Yes you can do that by using tab item and frames. You can have an idea using:
<TabItem Header="about" Name="aboutTab">
<TabControl>
<TabItem Header="REGISTRATION" Name="subTabRegistration">
<Grid>
<Frame NavigationUIVisibility="Hidden" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" ClipToBounds="True" JournalOwnership="Automatic" Source="Pages/register-activate.xaml" x:Name="frameRegistration" />
</Grid>
</TabItem>
</TabControl>
</TabItem>
I want to disply all my elipse in the same point using itemControl wpf. by default itemsControl use vertical stackpanel. there's a way to simply remove the StackPanel?
Thanks
Sure, you can give a custom ItemsPanel by either set one in your ItemsControl ControlTemplate, and using the IsItemsHost property to tell which of the panels is the receiver of the items.
<ItemsControl.Template>
<ControlTemplate>
<Canvas IsItemsHost="True"/>
</ControlTemplate>
</ItemsControl.Template>
or by supplying a custom ItemsPanel and telling the position in the template by an ItemsPresenter.
<ItemsControl.Template>
<ControlTemplate>
<ItemsPresenter/>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
This a pretty basic question that I can't find a simple answer to anywhere online. In a Windows Store xaml/c# app, if I create a New Templated Control named CustomControl1.cs.
Here's the default template as defined in the Generic.xaml file:
<Style TargetType="local:CustomControl1">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl1">
<Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I should be able to specify where child content lives by setting the Content property on the Border element above in either of the two following ways.
Specify content as Attribute
<Border Child="{TemplateBinding Content}" />
Specify content as Element
<Border>
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}" />
</Border>
But in either event, whenever I use the new control elsewhere, I'm unable to set the content property
Using this:
<local:CustomControl1>
<Button></Button>
</local:CustomControl1>
Gives off the two following errors:
Cannot add content to an object of type "CustomControl1"
The type 'CustomControl1' does not support direct content.
Make sure you derive your class from ContentControl and not just Control. This should resolve this for you. The default "Templated Control" item template is pretty generic to handle any case that folks might want, so if you want something more (in this case a Content control), just change to derive from ContentControl.
Hope this helps!
I'm using a pivot control and binding my collection of images to it. I'm having a problem with alignment of the photos.
If all the photos are landscape, they align at the top, and I am unable to use the gesture control anywhere below the photo.
If they are a mix of portrait/landscape, the images appear ok, until I rotate the device. Then the portrait images are extremely zoomed in, and the landscape images are located half way down the screen.
I'm new to WP7 development and the layout is still pretty foreign to me. Any assistance would be appreciated. I'm sure someone has to have created a basic photo viewer like this....
<controls:Pivot Name="photoPivot" Loaded="photoPivot_Loaded"
ItemsSource="{Binding _photos}">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<Grid Height="1" Width="1"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="{Binding photo_link}" />
</DataTemplate>
</controls:Pivot.ItemTemplate>
<controls:Pivot.ItemContainerStyle>
<Style TargetType="controls:PivotItem">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
</controls:Pivot.ItemContainerStyle>
</controls:Pivot>
I was able to solve this by removing all height/width definitions from the grid in the data template and the LayoutRoot grid.
I am trying to define a window template that can be used by windows in other assemblies. I define a window template and store it in resource dictionary in some assembly. After, I use this template in other assembly on window definition in XAML. It looks that the template is accepted and I can see updated window in VS-2010 designer but when I add a new control to this window, the control disappears from window but still exists in XAML code. I also tried to apply the same template explicitly and it works well.
Xaml code of generic.xaml in project that contains template definition, the ThemeInfo attribute is set and BuildAction property for this file is Page.
<ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly= {x:Type local:DialogResources}, ResourceId=DialogTemplate}">
<Border Width="Auto" Height="Auto" Name="windowFrame"
BorderBrush="#395984"
BorderThickness="1"
CornerRadius="0,20,20,20"
Background="AliceBlue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="1" Padding="5" Text="Template Window" FontWeight="Bold"/>
<Border Background="#B5CBEF" Grid.Row="1" CornerRadius="0,0,20,20" >
<AdornerDecorator>
<ContentPresenter/>
</AdornerDecorator>
</Border>
</Grid>
</Border>
</ControlTemplate>
DialogRespources - is an empty class that defined in MyProg.Resources assembly.
Now I use this template in other assembly like this:
In this window I add a button but I can't to see it. When I define the TemplateControl explicitly (without using resource) I can see it.
The other problem is that I get a following designer exception when use TargetType="{x:Type Window}" for template in resource: "'Window' ControlTemplate TargetType does not match templated type 'WindowInstance'." I could not find anything regarding this exception in Google.
Please, help me to understand what is wrong in my code?