Xiaopeng wang

I have GridView include two column and the first colum is applied with dataTemplate which make up of one checkBox and TextBlock. The dataTemplate is not available When I applied the "DisplayMemberBinding" import the xml data. The first column only show the string and not show the checkBox. I post the the part of the code. Pls help thk!

<ListView Name="CategoryList"Margin="16,59,39,35.9999999999999" IsSynchronizedWithCurrentItem="True" AllowDrop="false" ItemContainerStyle="{StaticResource MyContainerStyleKey}" ItemsSource="{Binding Source={StaticResource ConfigData}, XPath=Song}" >
<ListView.View>
<GridView ColumnHeaderContainerStyle="{DynamicResource GridViewColumnHeaderStyle}">


<GridViewColumn CellTemplate="{DynamicResource FileCategoryTemplate}" Header="{DynamicResource Archive_FileCategories}" Width="200" DisplayMemberBinding="{Binding XPath=@Category}" />


<GridViewColumn CellTemplate="{DynamicResource FileExtensionTemplate}" Header="{DynamicResource Archive_FileExtensions}" Width="600" DisplayMemberBinding="{Binding XPath=@Extension}" />


</GridView>
</ListView.View>
</ListView>




Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

lee d

when both celltemplate and displaymemberbinding are specified the later takes precedence




Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

xpwang_leo

Hi,Lee

Thanks for your reply.

I try to exchange their position and move the displaymemberbinding ahead it seems unuseful.

Would you like to tell me how to resolve it.

Leo






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

xpwang_leo

some ideas else

Leo






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

Yi-Lun Luo - MSFT

If the displaymemberbinding property is set, the celltemplate will be ignored, even if you exchange their position. You can remove the displaymemberbinding, instead put your binding inside the template. For example:

<CheckBox Content="{Binding XPath=@Category}" />






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

xpwang_leo

Yi-Lun

Thanks for your idea. But the question is that I can only use the DisplayMemberBinding property to set the content of the class GridViewColumn.

In the other world the class GridViewColumn have to use property DisplayMemberBinding. This is real problem for me, would you like give mor some ideas

Thanks!!!

Leo






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

Yi-Lun Luo - MSFT

Why do you have to use DisplayMemberBinding When you need to display non-text values, the CellTemplate is a better choice. Anyway, if you insist, you can modify your binding source, change the Catagory property to a CheckBox, and then create a value converter. Note: This is just an idea. I've not tested it.




Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

xpwang_leo

Hi,Yi-Lun

I don't have to use the DisplayMemberBinding and I only find it is an actual problem. So if I define the data in the same xaml file I will show you how I define these data.

Here are my data:

<XmlDataProvider x:Key="ConfigData" XPath="/Info">
<x:XData>
<Info xmlns="">
<Song Category="Email" Extension=".pst, .msg, .att, .mbm, .mim, .mime, .mlm, .wcm, .dbx, .pfc" />
<Song Category="Financial" Extension=".qdb, .qmd, .mn4, .mny, .tax, .txf, .qbw" />
<Song Category="Music" Extension=".wav, .mp3, .wma, .ogg, .aac, .m4a, .m4p, .wpl, .asx, .m3u" />
<Song Category="Photo" Extension=".jpg, .jpeg, .tif, .tiff, .bmp, .gif" />
<Song Category="Productivity" Extension=".xls, .doc, .ppt, .pps, .xlsx, .docx, .pptx, .ppsx, .pdf, .mpp, .wps, .wks, .wp, .wpd, .wp6" />
<Song Category="Video" Extension=".asf, .avi, .dv, .m1p, .m1v, .m2p, .m2v, .mov, .mp2, .mp4, .mpg, .mpeg, .mpv, .qt, .vbs, .wmv, .xtl" />
<Song Category="MyRecordedTV" Extension=".dvr-ms" />
</Info>
</x:XData>
</XmlDataProvider>

Here are my dataTemplate:

<DataTemplate x:Key="FileCategoryTemplate">
<StackPanel Orientation="Horizontal">
<CheckBox Name="FileChecked" IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}" Margin="0,1,4,1" VerticalAlignment="Center"/>
<TextBlock Text ="{Binding FileCategory}"/>

</StackPanel>
</DataTemplate>


<DataTemplate x:Key="FileExtensionTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text ="{Binding FileExtension}"/>
</StackPanel>
</DataTemplate>

Here are my application:

<ListView.View>
<GridView ColumnHeaderContainerStyle="{DynamicResource GridViewColumnHeaderStyle}">
<GridViewColumn CellTemplate="{DynamicResource FileCategoryTemplate}" Header="{DynamicResource Archive_FileCategories}" Width="200" DisplayMemberBinding="{Binding XPath=@Category}" />


<GridViewColumn CellTemplate="{DynamicResource FileExtensionTemplate}" Header="{DynamicResource Archive_FileExtensions}" Width="600" DisplayMemberBinding="{Binding XPath=@Extension}" />
</GridView>
</ListView.View>

As you know CellTemplate is only style and it only points out how the data show. I use the DisplayMemberBinding to import these data so as to show them in every line of GridView. Ok, My problem is that how can I import these data without using DisplayMemberBinding. If I use the DisplayMemberBinding The template FileCategoryTemplate will not show the checkBox.

Thanks!!!






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

Yi-Lun Luo - MSFT

Actually CellTemplate is not only style, you can import data. This works well on my computer:

<GridViewColumn CellTemplate="{DynamicResource FileCategoryTemplate}" />

Note there’s no DisplayMemberBinding. Well, for simplicity I removed the styles, you can of course keep them.

And here’s the CellTemplate:

<DataTemplate x:Key="FileCategoryTemplate">

<StackPanel Orientation="Horizontal">

<CheckBox Name="FileChecked" Content="{Binding XPath=@Category}"/>

</StackPanel>

</DataTemplate>

This will show your data.

If you don’t know much about data template, I recommend you read this: http://msdn2.microsoft.com/en-us/library/ms742521.aspx. Don’t worry if it looks complicated at first. As time pass by, you’ll understand it better and better. J






Re: Windows Presentation Foundation (WPF) Help!!! When I applied the "DisplayMemberBinding" import the xml data The dataTemplate is not available!!!

xpwang_leo

Hi, Yi-Lun

I am so appreciate for your reply.

I reference one Chinese aphorism : Your remarks are more inspiring (enlightening) than what I have read in ten years !!!

My puzzle has been resolved via your method.

Thanks again.