TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
minakshi khaire
NA
35
7.5k
i want to display image on image control when i select path
Feb 2 2018 4:25 AM
i want to display image on image control when i select selected path from listbox.
My code wpf is:
<TabItem Header="Documents" FontSize="16" Margin="-0,45,5,-45" Style="{DynamicResource TabItemStyle2}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="90"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.ColumnSpan="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Employee Document Details:" Grid.Column="0" Margin="5" Foreground="#ff5d9cec"/>
<Button Grid.Column="2" Margin="3" Height="40" Width="40"
Template="{StaticResource Add_Row_Button_Template}" ToolTip="Add new Row" />
<!--Click="AddDocumentClick"-->
<!--<Button Content="Add Document" x:Name="AddDocumentsDetails" Grid.Column="3"
Height="30" Width="120" Template="{DynamicResource ButtonControlTemplate1}" Margin="0,0,0,5"/>-->
<Rectangle Height="1" Stroke="Gray" StrokeThickness="1" Grid.Column="0" Grid.ColumnSpan="5" Grid.Row="1"/>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<!--<DataGrid AutoGenerateColumns="False" BorderBrush="Black" BorderThickness="2" Grid.Row="0" ColumnWidth="*"
CanUserReorderColumns="False"
CanUserSortColumns="False" Background="Transparent" CanUserDeleteRows="False" Foreground="Gray"
CanUserResizeRows="False" CanUserResizeColumns="False" x:Name="dataGrid2"
AreRowDetailsFrozen="True" AlternatingRowBackground="Transparent">>
<DataGrid.Columns>
<DataGridTextColumn Header="Sr.No." Width="50" Binding="{Binding SrNo}"/>
<DataGridTemplateColumn Header="Document" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="tb"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Browse" Width="70">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Upload" Foreground="Gray" Margin="2" Click="UploadButton"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>-->
<ListBox Name="lbFiles" Grid.Row="0" Margin="5" Height="300"
ItemsSource="{Binding Path=imgphoto}" />
<TextBlock Grid.Row="1" x:Name="tb"/>
<Button Content="upload" Grid.Row="2" Click="UploadButton" />
</Grid>
<Grid Grid.Column="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Border BorderBrush="Black" Margin="5" Grid.Column="1" BorderThickness="2" Height="500" >
<Image x:Name="imgphoto" Stretch="Uniform" Margin="10" Grid.Column="1" />
</Border>
</Grid>
</Grid>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Button Content="Save" Grid.Row="1" Grid.Column="1" Height="30" Width="150" Margin="5" Template="{StaticResource ButtonControlTemplateGreen}" />
<Button Content="View" Grid.Row="1" Grid.Column="3" Margin="5" Height="30" Width="150" Template="{StaticResource ButtonControlTemplateBlue}" />
<Button Content="Delete" Grid.Row="1" Grid.Column="5" Margin="5" Height="30" Width="150" Template="{StaticResource ButtonControlTemplateGreen}" />
<Button Content="Cancel" Grid.Row="1" Grid.Column="7" Margin="5" Height="30" Width="150" Template="{StaticResource ButtonControlTemplateBlue}" />
</Grid>
</Grid>
</TabItem>
</tabcontrol/>
My c# code:
public partial class MainWindow : Window
{
ObservableCollection<Person> People = new ObservableCollection<Person>();
//ObservableCollection<Employee> People2 = new ObservableCollection<Employee>();
public MainWindow()
{
InitializeComponent();
dataGrid1.ItemsSource = People;
//dataGrid2.ItemsSource = People2;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
People.Add(new Person());
}
public class Person
{
public string EducationClassName { get; set; }
//public DatePicker DateFrom { get; set; }
public DatePicker DateTo { get; set; }
public string NameOfSchoolOrUniversity { get; set; }
public string Certification { get; set; }
public string GradeObtained { get; set; }
//}
//public class Employee
//{
// public int srno { get; set; }
// public string Document { get; set; }
// public Uri Browse { get; set; }
//}
//private void AddDocumentClick(object sender, RoutedEventArgs e)
//{
// People2.Add(new Employee());
}
private void UploadButton(object sender, RoutedEventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
openfiledialog.Multiselect = true;
openfiledialog.Title = "Select a picture";
openfiledialog.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (openfiledialog.ShowDialog() == true)
{
imgphoto.Source = new BitmapImage(new Uri(openfiledialog.FileName));
string path = openfiledialog.FileName.ToString();
foreach (string filename in openfiledialog.FileNames) ;
tb.Text = openfiledialog.FileName;
lbFiles.Items.Add(tb.Text);
//lbFiles.Items.Add(Path.GetFileName(filename));
//.ItemsSource = path;
// textbox1.IsReadOnly.ToString(Path.filename);
}
}
}
}
My project's screen shot:
Please help me..........
Reply
Answers (
11
)
WPF application with MVVM
WPF stroke/outline of text not seeing namespace