|
i want to bind images horizontally using datagrid
i don't want to use listbox because i m binding images directly from sql server table on rowbinding event datagrid.
One person's data is another person's program.
--J.Walia
|
|
|
|
|
A list box can be used with an ItemsPanelTemplate tag and a StackPanel to achieve this[^].
If your binding is done correctly, I dont think you should need the rowbinding event of the datagrid.
Use an ObservableCollection to bind to the list box.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
Hi abhinav
thanks for reply
Actually i m binding images directly from datagrid. for this purpose i am generic handler.
i bind the images to image control on rowbinding event of datagrid.
In listbox i dint find rowbinding event.
http://dotnetcurry.com/ShowArticle.aspx?ID=264
One person's data is another person's program.
--J.Walia
|
|
|
|
|
J walia wrote: Actually i m binding images directly from datagrid. for this purpose i am generic handler.
i bind the images to image control on rowbinding event of datagrid.
So the bindings work but you need to arrange Image elements horizontally?
What are you trying to do once the Image elements have
their bindings?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i want arrange image controls horizontally
One person's data is another person's program.
--J.Walia
|
|
|
|
|
J walia wrote: i want arrange image controls horizontally
Grid, StackPanel, Canvas are some elements that can have child
elements arranged horizontally.
<StackPanel Orientation="Horizontal" >
<Image .../>
<Image .../>
<Image .../>
</StackPanel>
For data coming from a collection, you could use an ItemsControl or
derived.
Do you have an example or some details of what you want, or
something you tried that didn't work?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
but these controls does't have row binding event
One person's data is another person's program.
--J.Walia
|
|
|
|
|
J walia wrote: these controls does't have row binding event
What is a row binding event (what event are you referring to)
and why do you think you need it?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark
Please check this link
http://dotnetcurry.com/ShowArticle.aspx?ID=264
I have used same logic. please help now
i need this badly.
One person's data is another person's program.
--J.Walia
|
|
|
|
|
J walia wrote: I have used same logic.
Thanks.
So you are using the LoadingRow event....so what are you
trying to do in your LoadingRow event handler?
Do you have multiple images per row instead of one like the sample?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Again, look at the job board. This is not the place to post job opportunities.
|
|
|
|
|
Hi.
I've written the following XAML code for my ListView :
<ListView x:Name="ListView1" Background="#FFEEF3FA" >
<ListView.View>
<GridView>
<GridViewColumn x:Name="GridViewColumnName" Header="Name" Width="200" />
<GridViewColumn x:Name="GridViewColumnTags" Header="Tags" Width="100" />
<GridViewColumn x:Name="GridViewColumnLocation" Header="Location" Width="238" />
</GridView>
</ListView.View>
<ListViewItem>test1</ListViewItem>
<ListViewItem>test2</ListViewItem>
<ListViewItem>test3</ListViewItem>
<ListViewItem>test4</ListViewItem>
<ListViewItem>test5</ListViewItem>
<ListViewItem>test6</ListViewItem>
<ListViewItem>test7</ListViewItem>
<ListViewItem>test8</ListViewItem>
<ListViewItem>test9</ListViewItem>
<ListViewItem>test10</ListViewItem>
</ListView>
You can see the result of above code in this image : http://xs.to/image-CB3E_4B3BAE1D.jpg[^]
I wanna create a ListView with ListViewItem in XAML code like this : http://xs.to/image-7BBC_4B3BB199.jpg[^]
I don't know how I should do it !
Would you please guide me ?
Thanks in advance.
|
|
|
|
|
First, create a class that holds 3 properties:
using System.Windows;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
<big><big><big> public class MyClass
{
public string Prop1
{
get;
set;
}
public string Prop2
{
get;
set;
}
public string Prop3
{
get;
set;
}
}</big></big></big>
}
Next, you can define an array in your XAML then set that as your ItemsSource on your ListView. Then you use the DisplayMemberBinding property of each GridViewColumn to decide what you want to display in each column:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<big><big><big> xmlns:local="clr-namespace:WpfApplication1"</big></big></big>>
<big><big><big> <Window.Resources>
<x:Array x:Key="SomeData" Type="{x:Type local:MyClass}">
<local:MyClass Prop1="test1" Prop2="test2" Prop3="test3" />
<local:MyClass Prop1="test4" Prop2="test5" Prop3="test6" />
<local:MyClass Prop1="test7" Prop2="test8" Prop3="test9" />
<local:MyClass Prop1="test10" />
</x:Array>
</Window.Resources></big></big></big>
<Grid>
<ListView <big><big><big>ItemsSource="{StaticResource SomeData}"</big></big></big>>
<ListView.View>
<GridView>
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop1}"</big></big></big> Header="Name" Width="50" />
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop2}"</big></big></big> Header="Tags" Width="50" />
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop3}"</big></big></big> Header="Location" Width="50" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
If you REALLY want to specify each ListViewItem rather than setting the ItemsSource, then you could use this XAML instead:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Grid>
<ListView>
<ListView.View>
<GridView>
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop1}"</big></big></big> Header="Name" Width="50" />
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop2}"</big></big></big> Header="Tags" Width="50" />
<GridViewColumn <big><big><big>DisplayMemberBinding="{Binding Prop3}"</big></big></big> Header="Location" Width="50" />
</GridView>
</ListView.View>
<ListViewItem><big><big><big><local:MyClass Prop1="test1" Prop2="test2" Prop3="test3" /></big></big></big></ListViewItem>
<ListViewItem><big><big><big><local:MyClass Prop1="test4" Prop2="test5" Prop3="test6" /></big></big></big></ListViewItem>
<ListViewItem><big><big><big><local:MyClass Prop1="test7" Prop2="test8" Prop3="test9" /></big></big></big></ListViewItem>
<ListViewItem><big><big><big><local:MyClass Prop1="test10" /></big></big></big></ListViewItem>
</ListView>
</Grid>
</Window>
|
|
|
|
|
Excellent, Thanks aspdotnetdev.
I'm gonna to put an Object into the Property instead of string !
e.g : I want to put a StackPanel that contains an Image and a Label in Prop1.
What should I have done ?
Thanks in advance.
modified on Friday, January 1, 2010 3:20 AM
|
|
|
|
|
Use CellTemplate rather than DisplayMemberBinding.
Also, I highly recommend downloading the WPF Toolkit to use the DataGrid rather than the ListView. The DataGrid makes customizing visuals much easier. I believe it also has some additional options for sizing columns (percent, auto, etc.). You might also look at this quick stack overflow discussion of the advantages of using DataGrid.
|
|
|
|
|
|
Hey,
I want to have some surface on which the user can click, after which I get the coordinates so I can store them somewhere, and draw something on that location.
I've found ways to let a user draw on something, but not how to effectively get the coordinates. This is vital for the application I want to create though.
This is a C# application working with .Net 4.0 beta 2 and a WPF interface.
Any pointers or suggestions in the good direction are welcome - I really want to start with the real work on that app
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
This article (demo) here at The Code Project probability has every example you are looking for. It's a really nice diagramming application in the works.
WPF Diagram Designer - Part 2[^]
|
|
|
|
|
jeroen de dauw wrote: how to effectively get the coordinates
When handling mouse events, you can use the GetPosition() method
on the MouseEventArgs/MouseButtonEventArgs object to get the
coordinates relative to an element.
You can also use System.Windows.Input.Mouse.GetPosition() to
get the current coordinates relative to an element.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey guys,
I did search for such a method, and didn't find one. Guess why...
Somehow I managed to click the KeyDown event instead of the MouseDown one
Anyway, thanks for the helping
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
I'm probably doing something stupid wrong here, but my event handler for the MouseDown event is not getting called when I click on my canvas. Anyone an idea what I'm messing up?
Curious if I'm failing at C# or at WPF here
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
|
Hi all,
I am making use of a DataForm to display my data. I have made use of the DataForm edit template to customize the layout of the form. Data is returned and is being displayed within the DataForm. The problem is that, as soon as I start navigating (2 navigation clicks) with the DataFrom, only the ComboBox 'looses' it's binding on the SelectedItem (although it's selected item was data bound and then it just goes blank ).
The back end code consists of a generic list List<string> and a string variable that has the value of each data item that is returned.
..
public List<string> Category { get; set; }
public string CategoryName { get; set; }
..
The XAML code:
...
<dataFormToolkit:DataField DescriptionViewerPosition="Auto" LabelPosition="Left" LabelVisibility="Visible" Label="Category">
<ComboBox ItemsSource="{Binding Category}" SelectedItem="{Binding CategoryName, Mode=TwoWay}" />
</dataFormToolkit:DataField>
...
Any reason why this is happening and how I can fix it?
Many thanks in advance.
Kind regards
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
modified on Wednesday, December 30, 2009 8:36 AM
|
|
|
|
|
Hey. This problem has been bugging me a lot lately - Something really odd is happening in the framework. What's happening is the data field control is modifying the bindings on the control and re-setting them. Setting the SelectedItem works fine, but when it comes to re-set the ItemsSource property the binding for the *SelectedItem* property *vanishes* without a trace.
The only workaround I have at the moment is to make the ItemsSource binding TwoWay, and ensuring that the property it's bound to is read-only. This stops the code from modifying the ItemsSource binding.
However, I'm now finding that the bindings are disappearing under other circumstances as well (it looks like it's happening occasionally when there is more than 1 combo box in the form) - I haven't solved that one yet.
Cheers,
Mike
|
|
|
|