Solved

WPF XAML

Posted on 2009-04-01
5
575 Views
Last Modified: 2013-11-12
Hi,

Please go through my xaml.

For the control lstResult in the below attached xaml, I am just populating values from itemsource and this will populate values (FirstName,SurName,.....Address.Postcode) from item source.

1.My question is here for the list control lstResult, i need to have header consists of Firstname,SurName,Address1, Address2,Address 3,Address 4,Postcode like that.

2.I want to merge path expression Binding Path=CustomerTitle and Binding Path=FirstName and put into single text block. For example, i need to have text control which displays 'Mr FirstName'

Can you please answer this questions.

Thanks
Senthil
<UserControl x:Class="POS.Desktop.CustomerModule.LookupResults"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            xmlns:Resources="clr-namespace:POS.Desktop.Resources;assembly=POS.Desktop.Resources" 

             Height="200">

    

    <UserControl.Resources>

        <DataTemplate x:Key="ItemTemplate">

            <Grid Margin="20">

                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="Auto"></ColumnDefinition>

                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="{Binding Path=CustomerNo}" Background="White"/>

                <TextBlock Grid.Column="1"  Background="White"/>

                <TextBlock Grid.Column="2" Text="{Binding Path=CustomerTitle}" Background="White"/>

                <TextBlock Grid.Column="3" Text="{Binding Path=FirstName}" Background="White"/>

                <TextBlock Grid.Column="4" Text="{Binding Path=Surname}" Background="White"/>

                <TextBlock Grid.Column="5" Text="{Binding Path=Address.Line1}" Background="White"/>

                <TextBlock Grid.Column="6" Text="{Binding Path=Address.Line2}" Background="White"/>

                <TextBlock Grid.Column="7" Text="{Binding Path=Address.PostCode}" Background="White"/>

                <Button Click="Button_Click" Grid.Column="7" Content="Open..." />

            </Grid>

        </DataTemplate>
 

        <DataTemplate x:Key="SelectedTemplate">

            <Grid Margin="20">

                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="*"></ColumnDefinition>

                    <ColumnDefinition Width="Auto"></ColumnDefinition>

                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="{Binding Path=CustomerNo}" />

                <TextBlock Grid.Column="1" Text="{Binding Path=CustomerTitle}" />

                <TextBlock Grid.Column="2" Text="{Binding Path=FirstName}" />

                <TextBlock Grid.Column="3" Text="{Binding Path=Surname}" />

                <TextBlock Grid.Column="4" Text="{Binding Path=Address.Line1}" />

                <TextBlock Grid.Column="5" Text="{Binding Path=Address.Line2}" />

                <TextBlock Grid.Column="6" Text="{Binding Path=Address.PostCode}" />

                <Button Grid.Column="7" Content="Open..." />

            </Grid>

        </DataTemplate>
 

        <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">

            <Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}" />

            <Style.Triggers>

                <Trigger Property="IsSelected" Value="True">

                    <Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}" />

                </Trigger>

            </Style.Triggers>

        </Style>

    </UserControl.Resources>

    

    <Grid>

        <ListBox x:Name="lstResult" 

                 ItemContainerStyle="{StaticResource ContainerStyle}"

                 HorizontalContentAlignment="Stretch"

                 Style="{DynamicResource {x:Static Resources:VisualResources.PosListBoxStyleKey}}"

                 ItemsSource="{Binding}" HorizontalAlignment="Stretch">
 

        </ListBox>

    </Grid>

</UserControl>

Open in new window

0
Comment
Question by:senthilkannan19
  • 2
  • 2
5 Comments
 
LVL 16

Assisted Solution

by:TSmooth
TSmooth earned 50 total points
ID: 24042254
In response to question 2, you have 2 options that I'm aware of:
1.) Create a read only property on the class you are binding to that returns the concatenated string of title and first name. Then bind your textbox to that property.

2.) Bind the textbox to the parent object containing the "Mr." and "Firstname" properties and use a converter class to return the concatenated string.
0
 
LVL 8

Accepted Solution

by:
unmeshdave earned 200 total points
ID: 24043328
1.) first of all, when you need the functionality like listview, why you are using listbox?
2). use datatemplate in which show two textblock in dockpanel with orientation=horizontal . Bind each textblock with relavant datafield.
0
 

Author Comment

by:senthilkannan19
ID: 24047569
Can you please give me any code example guys?
0
 

Author Comment

by:senthilkannan19
ID: 24048024
1.My question is here for the list control lstResult, i need to have header consists of Firstname,SurName,Address1, Address2,Address 3,Address 4,Postcode like that.
0
 
LVL 8

Assisted Solution

by:unmeshdave
unmeshdave earned 200 total points
ID: 24050686
If you will use ListView not Listbox(as you need functionalities like Listview) then
<!-- Declare datatemplates in your resources like Window.Resources or Grid.Resources-->

=======================================

    

    <DataTemplate x:Key="FirstNameCell">

                    <TextBlock Text="{Binding Path=FirstName}"/>

        </DataTemplate>

    <DataTemplate x:Key="SirNameCell">

                    <TextBlock Text="{Binding Path=SirName}"/>

        </DataTemplate>

    <DataTemplate x:Key="Adress1Cell">

                    <TextBlock Text="{Binding Path=Address1}"/>

        </DataTemplate>

    <DataTemplate x:Key="Address2Cell">

                    <TextBlock Text="{Binding Path=Address2}"/>

        </DataTemplate>

===================

<ListView x:Name="lstResult" ">

            <ListView.View>

                <GridView>

                    <GridViewColumn Header="FirstName" Width="auto"  CellTemplate="{StaticResource FirstNameCell}" /> 

                    <GridViewColumn Header="SirName" Width="auto"  CellTemplate="{StaticResource SirNameCell}" />

                    <GridViewColumn Header="Address1" Width="auto"  CellTemplate="{StaticResource Address1Cell}" />

                    <GridViewColumn Header="Address2" Width="auto"   CellTemplate="{StaticResource Address2Cell}"/>

.

.

.

                </GridView>

            </ListView.View>

</ListView>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save copy of document in Word 4 76
MS Access (Newest One): Pulling Data out of a MS SQL DB 1 45
Problem to DocumentFormat 8 76
Post a good COM tutorial 1 50
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now