Image is not visible in Gridview in wpf
up vote
0
down vote
favorite
I am trying to display images along with data in listview data item.I am able to see the text item in the List view but not able see the image .I am binding Image with image file path.Same image path is working fine outside the listview in the same page.But inside the List view it is not showing the image .But the border(Yellow) surrounding the image control is visible in the list view .Please help to find the solution
<
ListView Name="lvUsers" Grid.Column="1" Grid.Row="1" Margin="0,5,0,0" Height="Auto"
Background="{x:Null}" BorderBrush="{x:Null}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True"
IsEnabled="True">
<ListView.View >
<GridView >
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill" Source="{Binding Path=DisplayedImage, Mode=Default}" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" DisplayMemberBinding="{Binding EmpName}">
<GridViewColumn.Header>
<GridViewColumnHeader Tag="EmpName" Click="lvUsersColumnHeader_Click">Name</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Border Width="30" Height="30" CornerRadius="10,10,10,10 " >
<Image x:Name="Avatar" Source="{Binding Path=DisplayedImage, Mode=Default}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</Grid>
</UserControl>
My code behind as follow:
Name space and page intiatization code:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
public ProjectTracker()
{
InitializeComponent();
List<DataTable> items = new List<DataTable>();
items.Add(loademp());
lvUsers.ItemsSource = loademp().DefaultView;
DataContext = new MainSideBar_viewModel();
}
Object in view model for image source binding :
public string DisplayedImage
{
get { return @"C:faisalXerox2014wpfgsktidP11376fs2.JPG"; }
}
c# wpf data-binding
add a comment |
up vote
0
down vote
favorite
I am trying to display images along with data in listview data item.I am able to see the text item in the List view but not able see the image .I am binding Image with image file path.Same image path is working fine outside the listview in the same page.But inside the List view it is not showing the image .But the border(Yellow) surrounding the image control is visible in the list view .Please help to find the solution
<
ListView Name="lvUsers" Grid.Column="1" Grid.Row="1" Margin="0,5,0,0" Height="Auto"
Background="{x:Null}" BorderBrush="{x:Null}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True"
IsEnabled="True">
<ListView.View >
<GridView >
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill" Source="{Binding Path=DisplayedImage, Mode=Default}" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" DisplayMemberBinding="{Binding EmpName}">
<GridViewColumn.Header>
<GridViewColumnHeader Tag="EmpName" Click="lvUsersColumnHeader_Click">Name</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Border Width="30" Height="30" CornerRadius="10,10,10,10 " >
<Image x:Name="Avatar" Source="{Binding Path=DisplayedImage, Mode=Default}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</Grid>
</UserControl>
My code behind as follow:
Name space and page intiatization code:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
public ProjectTracker()
{
InitializeComponent();
List<DataTable> items = new List<DataTable>();
items.Add(loademp());
lvUsers.ItemsSource = loademp().DefaultView;
DataContext = new MainSideBar_viewModel();
}
Object in view model for image source binding :
public string DisplayedImage
{
get { return @"C:faisalXerox2014wpfgsktidP11376fs2.JPG"; }
}
c# wpf data-binding
1
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to writelvUsers.ItemsSource = items;
? And isDisplayedImage
a property of DataTable?
– Clemens
Nov 21 at 19:50
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to display images along with data in listview data item.I am able to see the text item in the List view but not able see the image .I am binding Image with image file path.Same image path is working fine outside the listview in the same page.But inside the List view it is not showing the image .But the border(Yellow) surrounding the image control is visible in the list view .Please help to find the solution
<
ListView Name="lvUsers" Grid.Column="1" Grid.Row="1" Margin="0,5,0,0" Height="Auto"
Background="{x:Null}" BorderBrush="{x:Null}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True"
IsEnabled="True">
<ListView.View >
<GridView >
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill" Source="{Binding Path=DisplayedImage, Mode=Default}" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" DisplayMemberBinding="{Binding EmpName}">
<GridViewColumn.Header>
<GridViewColumnHeader Tag="EmpName" Click="lvUsersColumnHeader_Click">Name</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Border Width="30" Height="30" CornerRadius="10,10,10,10 " >
<Image x:Name="Avatar" Source="{Binding Path=DisplayedImage, Mode=Default}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</Grid>
</UserControl>
My code behind as follow:
Name space and page intiatization code:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
public ProjectTracker()
{
InitializeComponent();
List<DataTable> items = new List<DataTable>();
items.Add(loademp());
lvUsers.ItemsSource = loademp().DefaultView;
DataContext = new MainSideBar_viewModel();
}
Object in view model for image source binding :
public string DisplayedImage
{
get { return @"C:faisalXerox2014wpfgsktidP11376fs2.JPG"; }
}
c# wpf data-binding
I am trying to display images along with data in listview data item.I am able to see the text item in the List view but not able see the image .I am binding Image with image file path.Same image path is working fine outside the listview in the same page.But inside the List view it is not showing the image .But the border(Yellow) surrounding the image control is visible in the list view .Please help to find the solution
<
ListView Name="lvUsers" Grid.Column="1" Grid.Row="1" Margin="0,5,0,0" Height="Auto"
Background="{x:Null}" BorderBrush="{x:Null}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True"
IsEnabled="True">
<ListView.View >
<GridView >
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill" Source="{Binding Path=DisplayedImage, Mode=Default}" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" DisplayMemberBinding="{Binding EmpName}">
<GridViewColumn.Header>
<GridViewColumnHeader Tag="EmpName" Click="lvUsersColumnHeader_Click">Name</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Border Width="30" Height="30" CornerRadius="10,10,10,10 " >
<Image x:Name="Avatar" Source="{Binding Path=DisplayedImage, Mode=Default}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</Grid>
</UserControl>
My code behind as follow:
Name space and page intiatization code:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
public ProjectTracker()
{
InitializeComponent();
List<DataTable> items = new List<DataTable>();
items.Add(loademp());
lvUsers.ItemsSource = loademp().DefaultView;
DataContext = new MainSideBar_viewModel();
}
Object in view model for image source binding :
public string DisplayedImage
{
get { return @"C:faisalXerox2014wpfgsktidP11376fs2.JPG"; }
}
c# wpf data-binding
c# wpf data-binding
edited Nov 21 at 19:46
asked Nov 21 at 19:28
Faisal Thayyil
216
216
1
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to writelvUsers.ItemsSource = items;
? And isDisplayedImage
a property of DataTable?
– Clemens
Nov 21 at 19:50
add a comment |
1
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to writelvUsers.ItemsSource = items;
? And isDisplayedImage
a property of DataTable?
– Clemens
Nov 21 at 19:50
1
1
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to write lvUsers.ItemsSource = items;
? And is DisplayedImage
a property of DataTable?– Clemens
Nov 21 at 19:50
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to write lvUsers.ItemsSource = items;
? And is DisplayedImage
a property of DataTable?– Clemens
Nov 21 at 19:50
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You could use a RelativeSource
to bind to a property of the view model from within the CellTemplate
:
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill"
Source="{Binding Path=DataContext.DisplayedImage, RelativeSource={RelativeSource AncestorType=ListView}}"
HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
The default DataContext
of the Image
is an item in the ItemsSource
and this one has no DisplayedImage
property apparently.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You could use a RelativeSource
to bind to a property of the view model from within the CellTemplate
:
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill"
Source="{Binding Path=DataContext.DisplayedImage, RelativeSource={RelativeSource AncestorType=ListView}}"
HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
The default DataContext
of the Image
is an item in the ItemsSource
and this one has no DisplayedImage
property apparently.
add a comment |
up vote
0
down vote
accepted
You could use a RelativeSource
to bind to a property of the view model from within the CellTemplate
:
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill"
Source="{Binding Path=DataContext.DisplayedImage, RelativeSource={RelativeSource AncestorType=ListView}}"
HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
The default DataContext
of the Image
is an item in the ItemsSource
and this one has no DisplayedImage
property apparently.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You could use a RelativeSource
to bind to a property of the view model from within the CellTemplate
:
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill"
Source="{Binding Path=DataContext.DisplayedImage, RelativeSource={RelativeSource AncestorType=ListView}}"
HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
The default DataContext
of the Image
is an item in the ItemsSource
and this one has no DisplayedImage
property apparently.
You could use a RelativeSource
to bind to a property of the view model from within the CellTemplate
:
<GridViewColumn Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border Width="30" Height="30" Background="Yellow" >
<Image Width="10" Height="10" Stretch="Fill"
Source="{Binding Path=DataContext.DisplayedImage, RelativeSource={RelativeSource AncestorType=ListView}}"
HorizontalAlignment="Center" Margin="0,0,0,0" />
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
The default DataContext
of the Image
is an item in the ItemsSource
and this one has no DisplayedImage
property apparently.
answered Nov 22 at 12:54
mm8
80k81731
80k81731
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419273%2fimage-is-not-visible-in-gridview-in-wpf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
lvUsers.ItemsSource = loademp().DefaultView;
makes no sense at all. Did you perhaps intend to writelvUsers.ItemsSource = items;
? And isDisplayedImage
a property of DataTable?– Clemens
Nov 21 at 19:50