|
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.
|
|
|
|
|
Thanks for reply..
I have tried Webbrowser1.source = null;
but its not releasing file.
|
|
|
|
|
Hi
I am looking for a open source project which is a vector editor (like MS Visio)using Silverlight. Any information will be appreciated.
Best regards,
|
|
|
|
|
I have some code written as such:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if ((object)Template != null)
{
CheckBox chkBox = Template.FindName("chkBox", this) as CheckBox;
}
}
at runtime, this code works perfectly fine and everything is peachy. Inside of the designer, it apperently fails to find the CheckBox. I'm not really sure why... I can find parts that are in the "standard" template like Border "Bd" and ContentPresenter "PART_Header", but nothing in my overridden template.
Any ideas?
|
|
|
|
|
Hmm... kind of weird, but it seems like triggers aren't executed in the designer or something? I set the template via a trigger. If I hard code the template instead, it does show up... so it seems like my trigger isn't getting executed and its not picking my template.
|
|
|
|
|
OK, first of all have you added the template parts you expect to the class? You'd do this normally like:
[TemplatePart(Name="PART_Box", Type=typeof(CheckBox)] Then, have you set the metadata through the DefaultStyleKey ?
DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeViewEx), new FrameworkPropertyMetadata(typeof(TreeViewEx)));
|
|
|
|
|
Isn't TemplatePartAttribute only used by designers like Expression Blend when you go to style the control? At least, thats my understanding of the attribute.
Anyways, what I was doing was setting the template via a trigger:
<Trigger Property="internal:UIHelper.IsAeroTheme" Value="True">
<Setter Property="Template" Value="{StaticResource AeroTreeViewItemTemplate}" />
</Trigger>
<Trigger Property="internal:UIHelper.IsAeroTheme" Value="False">
<Setter Property="Template" Value="{StaticResource TreeViewItemTemplate}" />
</Trigger>
These triggers get executed at runtime, but they don't seem to get executed at design time, so as far as the designer is concerned, I'm using the standard control template.
I just added this code to my TreeViewItem constructor:
if (DesignerProperties.GetIsInDesignMode(this))
{
if (Internal.UIHelper.GetIsAeroTheme(this))
Template = FindResource("AeroTreeViewItemTemplate") as ControlTemplate;
else
Template = FindResource("TreeViewItemTemplate") as ControlTemplate;
}
and it seems to have solved the problem.
|
|
|
|
|
How can I Changing domain host for silverlight and WCF
|
|
|
|
|
Hello all,
I'm building an app for WP7 (but because my problem seems related to Silverlight/WPF things, I'm asking here). I have a slider wich values are updated every x milliseconds. This leads to unwanted behaviour when the user is dragging the slider to another position. Therefor, I created a new class that inherits from the Slider class, named BusySlider (see below). The problem is now, that my SliderBusy property always seems to be false, even when I'm actually dragging the slider... Any suggestions?
The BusySlider.cs
public class BusySlider : Slider
{
public bool SliderBusy
{
get;
private set;
}
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
this.SliderBusy = true;
base.OnMouseLeftButtonDown(e);
}
protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
this.SliderBusy = false;
}
}
And here is a frangment of my Dispatcher.BeginInvoke where the slider gets updated;
Dispatcher.BeginInvoke(new Action(delegate()
{
...
if (!slidePosition.SliderBusy)
{
slidePosition.Maximum = (double)state.CurrentTrack.Length;
slidePosition.Value = (double)state.CurrentTrack.Position;
}
}));
Thanks in advance,
MadMatt
|
|
|
|
|
Hello,
I very new to WPF but i have a little experience in MFC.
I am trying to create a simple GUI based app. In MFC when i add new button for example and i go to button properties i can see a list of avaliable events button can send in WPF i cant find such list.
How can i add event handlers to controls beside doing it directly in the XML file?
Thanks!!!
|
|
|
|
|
If you set the Name property of your button then you can use it in your code behind. Eg.:
Xaml:
<Button Name="myButton" Content="Click Me!"/>
Code behind:
myButton.Click += OnMyButtonClick;
I would suggest you look into commands if you haven't done so already.
Sacha Barber has written a good series of articles which introduces the WPF concepts here is a link to the 3rd which covers commands
WPF: A Beginner's guide: Part 3 of n[^]
|
|
|
|
|
If you are using Visual Studio 2010, open the window/user control in the designer and then select the control you want to add an event for. In the properties panel, there's an Event tab that you can use to choose the event.
|
|
|
|