|
How do I populate that type of Treeview? I've created a listview such like you said for my MRU list I need to populate the Treeview with sorted data by Alphabetic base letter A-Z then Lastname, Firstname middle intial. I'm already using a collection:
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Manufactured_Housing_Manager
{
public class tvIndex
{
private string _index;
public string Index
{
get { return _index; }
set { _index = value; }
}
private ObservableCollection<Contact> _contacts;
public ObservableCollection<Contact> Contacts
{
get
{
if (_contacts == null)
_contacts = new ObservableCollection<Contact>();
return _contacts;
}
}
public tvIndex()
{
}
public tvIndex(
string indexx,
ObservableCollection<Contact> contacts)
{
_index = indexx;
_contacts = contacts;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Manufactured_Housing_Manager
{
public class Contact
{
private string _name;
private int _id;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public Contact()
{
}
public Contact(string name, int id)
{
_name = name;
_id = id;
}
}
}
My Xaml is this:
<UserControl x:Class="Manufactured_Housing_Manager.Outlookbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Manufactured_Housing_Manager"
mc:Ignorable="d"
>
<UserControl.Resources>
<Style x:Key="TreeViewStyle1" TargetType="{x:Type TreeView}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeView}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
<ScrollViewer x:Name="_tv_scrollviewer_" Background="{TemplateBinding Background}" CanContentScroll="True" Focusable="false" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" Template="{DynamicResource ScrollViewerControlTemplate1}" >
<ItemsPresenter ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True"/>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
<Setter Property="CanContentScroll" TargetName="_tv_scrollviewer_" Value="true"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<!--
<HierarchicalDataTemplate x:Key="ChildTemplate">
<StackPanel Orientation="Horizontal">
<Image x:Name="img2" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Name}" Margin="5,0" ToolTip="{Binding Path=Name}"/>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="MyTreeViewStyle"
ItemsSource="{Binding Path=Contacts}"
ItemTemplate="{StaticResource ChildTemplate}">
<!--
<StackPanel Orientation="Horizontal">
<Image x:Name="img" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Index}" Margin="5,0" ToolTip="{Binding Path=Index}"/>
</StackPanel>
</HierarchicalDataTemplate>
</UserControl.Resources>
<DockPanel>
<Grid>
<Border Margin="5,5,0,0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="lightGray" CornerRadius="3" Height="24" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<TextBlock Margin ="5,0" Name="tbOutlookBar" VerticalAlignment="Center" Text="Contacts" Foreground="#FF355AAF" FontSize="14" />
</Border>
<Border Name="OutlookBarInfo" DockPanel.Dock="Left" Margin="5,28,0,0" Background="White" Height="24" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="1" BorderBrush="lightGray" CornerRadius="3">
<TextBlock Margin ="5,0" Name="tbOutlookBarInfo" VerticalAlignment="Center" Text=" " Foreground="Black" FontSize="12" />
</Border>
<TabControl Margin="5,52,0,5" Grid.RowSpan="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" TabStripPlacement="Bottom" Style="{DynamicResource OutlookTabControlStyle}" >
<TabItem Height="24" Style="{DynamicResource OutlookTabItemStyle}" Background="{DynamicResource OutlookButtonBackground}" Foreground="{DynamicResource OutlookButtonForeground}" ToolTip="Contacts">
<!--
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Name="img" Source="Images/contact16.png" Stretch="Fill" Height="16" Width="16" Margin="0,3" />
<TextBlock Text="Contacts" Margin="3,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid>
<TreeView ItemsSource="{x:Static local:RibbonControl.contactdata}" x:Name="MyTreeView" ItemTemplate="{StaticResource MyTreeViewStyle}" ScrollViewer.CanContentScroll="True" Style="{DynamicResource TreeViewStyle1}">
<!--
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</Grid>
</TabItem>
<TabItem Grid.ColumnSpan="2" Height="24" Style="{DynamicResource OutlookTabItemStyle}" Background="{DynamicResource OutlookButtonBackground}" Foreground="{DynamicResource OutlookButtonForeground}" ToolTip="Calendar">
<!--
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Name="img2" Source="Images/calendar16.png" Stretch="Fill" Height="16" Width="16" Margin="0,3" />
<TextBlock Text="Calendar" Margin="3,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid>
<!--
</Grid>
</TabItem>
</TabControl>
</Grid>
</DockPanel>
</UserControl>
almost forgot the code inside the User Control:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Manufactured_Housing_Manager;
namespace Manufactured_Housing_Manager
{
public partial class Outlookbar : UserControl
{
public DataTable dtContacts = new DataTable();
public DataTable dtDealerPacks = new DataTable();
public DataTable dtServices = new DataTable();
public DataRow rowContacts;
public DataRow rowDealerPacks;
public DataRow rowServices;
public string filename;
public string connectionString;
static public ObservableCollection<Contact> contactdata;
public Outlookbar()
{
InitializeComponent();
}
#region Update TreeView
private void updateTreeview()
{
if (Properties.Settings.Default.dbOpen)
{
for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
{
MyTreeView.Items.Add(new tvIndex(Convert.ToString((char)(i)), contactdata));
contactdata = new ObservableCollection<Contact>();
string sContactsName = null;
foreach (DataRow rowContacts in Properties.Settings.Default.DtContacts.Rows)
{
sContactsName = string.Concat(rowContacts["LastName"].ToString(), ", ", rowContacts["FirstName"].ToString());
if (!(System.Convert.IsDBNull(rowContacts["MiddleInitial"].ToString())))
{
if (!(rowContacts["MiddleInitial"].ToString() == ""))
sContactsName = string.Concat(sContactsName, " ", rowContacts["MiddleInitial"].ToString(), ".");
}
if (left(sContactsName, 1) == Convert.ToString((char)(i + 1)))
{
string temp = rowContacts["ContactID"].ToString();
contactdata.Add(new Contact(sContactsName, Convert.ToInt32(temp)));
}
}
}
if (Properties.Settings.Default.DtContacts.Rows.Count < 2)
{
tbOutlookBarInfo.Text = Properties.Settings.Default.DtContacts.Rows.Count + " Contact";
tbOutlookBarInfo.ToolTip = Properties.Settings.Default.DtContacts.Rows.Count + " Contact";
}
else
{
tbOutlookBarInfo.Text = Properties.Settings.Default.DtContacts.Rows.Count + " Contacts";
tbOutlookBarInfo.ToolTip = Properties.Settings.Default.DtContacts.Rows.Count + " Contacts";
}
}
}
#endregion
}
}
modified on Friday, August 12, 2011 1:36 PM
|
|
|
|
|
You mean, you want your tree to look like:
A
ALastName, AFirstName
ALastName2, AFirstName2
B
BLastName, BFirstName
BLastName2, BFirstName
?
|
|
|
|
|
Yeah I already have this doing it but not in this wpf version. I was hosting everything inside one form and had several classes. Now I'm trying to properly create user controls for the ribbon the treeview/outlook bar, statusbar, and tabs which will display records. Basically I'm trying to improve my coding techniques and more correctly adapt to MVVM style. Old dog trying to learn new tricks.
|
|
|
|
|
Haha... yeah, MVVM is a learning curve on top of the WPF learning curve. Trust me though, I come from the MFC / C++ world and did a bit of time in the C# / Winforms world... the WPF / MVVM way is by far the best. It results in *really* clean code.
Anyways...
Your data structure should kind of try to closely mirror how you want it in the tree. Obviously we aren't going to be modifying the alphabet any time soon, so we have 26 root nodes. I'd probably try to store it in something like:
public class ContactCollection : ObservableCollection<Contact>
The reason you need to do that is because XAML doesn't work well with generics.
SortedDictionary<char, ContactCollection>
so you'll populate the sorted dictionary with keys 'A' through 'Z' and new up an ContactCollection as the value. Then populate each ContactCollection with the names matching that letter. There is a little known trick to sort the ObservableCollections after you populate them. You derive a class from ObservableCollection<t> and add a method like this:
public void Sort(Comparison<T> comparison)
{
((List<T>)Items).Sort(comparison);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
Then your HierachialDataTemplate would just specify Key as the top level display binding and Values as the ItemsSource. Another HierachialDataTemplate would be typed for Contact and have the name as the display value.
This all might not make sense now, but once you get going, it will.
|
|
|
|
|
Kind of understand some but still confused. Below is the class I'm constructing
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace Manufactured_Housing_Manager
{
public class ContactCollection : ObservableCollection<Contact>
{
#region left, right, mid string functions
public static string left(string param, int length)
{
string result = param.Substring(0, length);
return result;
}
public static string mid(string param, int startIndex, int length)
{
string result = param.Substring(startIndex, length);
return result;
}
public static string right(string param, int length)
{
string result = param.Substring(param.Length - length, length);
return result;
}
#endregion
public ContactCollection() : base()
{
Add(new Contact("Davis, Adam T.", 0));
Add(new Contact("Zappa, Frank M.", 1));
Add(new Contact("Henry, Victor", 2));
Add(new Contact("Vern, Jules W.", 3));
}
}
public class Contact
{
private string _name;
private int _id;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public Contact()
{
}
public Contact(string name, int id)
{
_name = name;
_id = id;
}
}
}
Thing is I need to open my OLEDB Database to populate my dataset then I populate ObservableCollection<contact> with the names from each Contact in my database. I used the following code in the past to populate the tree and concate the names into one name information field I used to display.
for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
{
MyTreeView.Items.Add(new tvIndex(Convert.ToString((char)(i)), contactdata));
contactdata = new ObservableCollection<Contact>();
string sContactsName = null;
foreach (DataRow rowContacts in Properties.Settings.Default.DtContacts.Rows)
{
sContactsName = string.Concat(rowContacts["LastName"].ToString(), ", ", rowContacts["FirstName"].ToString());
if (!(System.Convert.IsDBNull(rowContacts["MiddleInitial"].ToString())))
{
if (!(rowContacts["MiddleInitial"].ToString() == ""))
sContactsName = string.Concat(sContactsName, " ", rowContacts["MiddleInitial"].ToString(), ".");
}
if (left(sContactsName, 1) == Convert.ToString((char)(i + 1)))
{
string temp = rowContacts["ContactID"].ToString();
contactdata.Add(new Contact(sContactsName, Convert.ToInt32(temp)));
}
}
In this way I simply added the base A-Z to the parent Node in the Treeview and then bound childnodes to the contactdata name and assigned the id to pull up the record.
My confusion stems from trying to implement the proper way of doing the same thing in this new public class based on ContactCollection : ObservableCollection<contact>.
As you can see I added a base which can manually add names and id's to the Collection. This gives me a certain amount of sample data to see if binding is correct. I should place my code here that imports my Dataset information, Concats the Last,First,MI into one name value and gives the id.
modified on Friday, August 12, 2011 4:35 PM
|
|
|
|
|
Ok, so your ROOT object is going to be a:
SortedDictionary<char, ContactCollection>
So you would do something like:
SortedDictionary<char, ContactCollection> dict = new SortedDictionary<char, ContactCollection>();
for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
{
ContactCollection cc = new ContactCollection();
foreach (...)
{
}
dict.Add(System.Convert.ToChar(i), cc);
}
tv.ItemsSource = dict;
Your contact object also needs to implement INotifyPropertyChanged for this all to work correctly.
Report what your tree looks like on the screen and we can tweak the HierarchialDataTemplate to display the right content.
|
|
|
|
|
One last problem I think. How do I get tv.ItemsSource = dict;
to work. I get, An object reference is required for the non-static field, method, or property 'Manufactured_Housing_Manager.Outlookbar.MyTreeView'
I tried adding this to the tope of this class
using tv = Manufactured_Housing_Manager.Outlookbar;
also this is my xaml for binding
it's inside Outlookbar.xaml
<HierarchicalDataTemplate x:Key="ChildTemplate">
<StackPanel Orientation="Horizontal">
<Image x:Name="img2" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Name}" Margin="5,0" ToolTip="{Binding Path=Name}"/>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="MyTreeViewStyle"
ItemsSource="{Binding Path=Contact}"
ItemTemplate="{StaticResource ChildTemplate}">
<!--
<StackPanel Orientation="Horizontal">
<Image x:Name="img" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Index}" Margin="5,0" ToolTip="{Binding Path=Index}"/>
</StackPanel>
</HierarchicalDataTemplate>
modified on Friday, August 12, 2011 7:49 PM
|
|
|
|
|
I know I'm over thinking this. The whole Observable Collections thing is new to me. I'm confusing myself and getting discouraged. I created a hierarchical observable collection that worked before. but populating the class with data from my user selected OLE database was done outside the class. I can vaguely see how this is supposed to work , I'm just not visualizing the code to make it happen very well.
All of you help has been and is appreciated.
|
|
|
|
|
I was just showing you what property you needed to set. In proper MVVM, you don't set the ItemsSource explicitly. You just return it from your ViewModel.
public SortedDictionary<char, observablecollection<contact="">> ItemsSource
{
get
{
if (_dict == null)
{
// create the dictionary and observable collections here and
// store in _dict
}
return _dict;
}
then your XAML's DataContext should point to your ViewModel.
Then you can just do:
<treeview itemssource="{Binding" itemssource}="">
and your tree should be built for you.
|
|
|
|
|
You were talking about my needing to implement INotifyPropertyChanged, I've tried to use this before but I never was able to get it to work properly. How do you implement it and respond to it? I know that if I add or remove an item from my collection it will flag the INotifyPropertyChanged event. and I know that if I setup a function to respond to this it will run the code within it. But how do I use it actually?
|
|
|
|
|
If you use ObservableCollection, that already implements INotifyCOLLECTIONChanged for you. That will automatically update the UI when an item is added or removed. Your Contact object needs to implement INotifyPROPERTYChanged so the UI knows when a property of the contact object has changed. See this for a basic example: http://msdn.microsoft.com/en-us/library/ms229614.aspx[^].
For both INotifyPropertyChanged and INotifyCollectionChanged, you do not need to do anything else beyond implement the interfaces. When you bind to stuff, the WPF infrastructure will subscribe to the necessary events and do its thing for you.
|
|
|
|
|
This is what I came up with
using System;
using System.Data;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Manufactured_Housing_Manager
{
public class Contact : INotifyPropertyChanged
{
private string _name = String.Empty;
private int _id = 0;
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public string Name
{
get { return this._name; }
set
{
if (value != this._name)
{
this._name = value;
NotifyPropertyChanged("Name");
}
}
}
public int Id
{
get { return this._id; }
set
{
if (value != this._id)
{
this._id = value;
NotifyPropertyChanged("Id");
}
}
}
public Contact()
{
}
public Contact(string name, int id)
{
_name = name;
_id = id;
}
}
}
My Xaml code is
<HierarchicalDataTemplate x:Key="ChildTemplate">
<StackPanel Orientation="Horizontal">
<Image x:Name="img2" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Index}" Margin="5,0" ToolTip="{Binding Path=Index}"/>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="MyTreeViewStyle"
ItemsSource="{Binding Path=Contacts}"
ItemTemplate="{StaticResource ChildTemplate}">
<!--
<StackPanel Orientation="Horizontal">
<Image x:Name="img" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
<TextBlock Text="{Binding Path=Name}" Margin="5,0" ToolTip="{Binding Path=Name}"/>
</StackPanel>
</HierarchicalDataTemplate>
and the code Inside the UserControl is like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace Manufactured_Housing_Manager
{
public partial class Outlookbar : UserControl
{
static public ObservableCollection<Contact> Contacts = new ObservableCollection<Contact>();
public Outlookbar()
{
InitializeComponent();
InitializeTreeview();
}
#region left, right, mid string functions
public static string left(string param, int length)
{
string result = param.Substring(0, length);
return result;
}
public static string mid(string param, int startIndex, int length)
{
string result = param.Substring(startIndex, length);
return result;
}
public static string right(string param, int length)
{
string result = param.Substring(param.Length - length, length);
return result;
}
#endregion
private void InitializeTreeview()
{
Contacts.Add(new Contact("Davis, Adam T.", 1));
Contacts.Add(new Contact("Zappa, Frank", 2));
myTreeView.DataContext = Contacts;
}
}
}
In this way I can see the 2 contacts I have manually added but I still don't know how to get the base a-z stucture setup right in my Collection. also need to figure out how to only populate the treeview after I have opened the oledb database and populated the dataset.
This all works fine if I have everything in one class form but by having seperate usercontrols it's prving to be more difficult to do. If I had a static database to bind too it might be easier but I am allowing for user selected databases.
|
|
|
|
|
I have told you how a few times now and even gave you the code last time.
You need to have *26* ObservableCollection<Contact>'s.
Your *ROOT* object needs to be a SortedDictionary<char, ObservableCollection<Contact>>.
You will insert 26 entries into the sorted dictionary. Key is 'A' - 'Z' and the value is a new ObservableCollection<Contact> that contains the last names starting with that key.
|
|
|
|
|
Thanks for all the help I have it working now!
|
|
|
|
|
Hello,
Listbox control is being populated from the xml file using WCF.
As I place the items inside the listbox, I also would like to assign a tag for each item.
How can I dynamically populate the tag for each item in the list please?
Thanks
|
|
|
|
|
There are several ways to do waht you want. I suppose the most application answer would be to ask what you want to set the tag to. It can be any object, and you could use data binding to accomplish your goal.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hi,
How is it possible to fill a listbox with a colour?
I have populated the listbox but using the background colour does not fill all the background of each item.
How is this solved please?
Thanks
|
|
|
|
|
Try setting the item background to tansparent.
The chase down each element in item and make them transparent as well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hello Everyone,
I am viewing a pdf file which is generated in Temp folder in WebBrowser in WPF.
After viewing that there is a button for deleting that file. But while doing
File.Delete(filePath);
It gives me an error of Access denied.File is used by another process.
It is a AcrRdr which is locking the PDF file.but how to delete that file?
Thanks In Advance,
Ashish
|
|
|
|
|
I believe you must close the file so that it is no longer being viewed within the webbrowser, then you should be able to delete it.
|
|
|
|
|
Thanks,
I have done WebBrowser.Dispose(); and it releases the file.
But the webbrowser variable declared in XAML. I need to view another new file again it will not work since the object is Disposed.
Can you help me out how can I release PDF file? I have surfed on google It says AcrRdr holds the file since it is the last file.There is nothing where the browser can be redirected.
Help Needed please.
Regards,
Ashish
|
|
|
|
|
When you do WebBrower.Dispose(), you are "throwing out" your Web Browser control and all its content into the "trash can". All you have to do to release the PDF file it to close the file stream - something like pdfFileStream.Close(), with this you will be able to delete the PDF file and view another PDF file in your web browser
|
|
|
|
|
I am using
webbrowser1.source = filepath;
so there is not anything like filestream..
|
|
|
|
|
Before you delete set webbrowser1.source = null; or try = ""; the point is the system sees it as being used by the webbrowser control and therefore won't allow it to be deleted.
|
|
|
|
|