Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

Creating a dynamically 3D model in XAML

$
0
0

Hello all.<o:p></o:p>

I would like to ask some advice
about how to create dynamically 3D models using XAML and C#.<o:p></o:p>

Basically the program will
import two .dxf files(Autocad). It will extract the coordinates of a
semi-polyhedron  from one, and angle orientations and coordinates from the
other. I am saying semi-polyhedron because the coordinates will not completely
define it. It will need the information from the second.dxf file in order to
complete the solid. Therefore, I will have to calculate the equation of planes
using the information of the second .dxf and intersect them with coordinates of
the first .dxf file. I know it looks confusing , ant it is. <o:p></o:p>

I will have to render both the
coordinates and the planes, and let the user move the planes to fit in the
coordinates finally defining the polyhedron in the screen. This is only the
first step of the process and I will stop here for now so things don't turn
even more complex.<o:p></o:p>

Any suggestions will be very
much appreciated. If the description is not clear please do not hesitate to ask
any question you might have.<o:p></o:p>

I saw an old post but it didn't
helped much http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a2aef4db-d2d8-40ac-a61a-5e2ba64cfb57/<o:p></o:p>



Jair Santos


Weird performance problem with Shapes.Path

$
0
0

Hi,

I got a weird performance issue with the System.Windows.Shapes.Path class.

I have a loop creating about 40,000 paths into a Canvas. There are one or two handfuls of different Brushes used for the objects.

When I create a new SolidColorBrush for each iteration, the loop takes about 3.5 seconds:

Brush brStroke = null;
for (uint index = 0; index < count; index++)
   {
   System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();

   path.Data = GetPathData();

   brStroke = new SolidColorBrush(GetColor(index));

   path.Stroke = brStroke;
   path.StrokeThickness = thickness;
   canvas.Children.Add(path);
   }

I thought I could speed this up a bit by creating a dictionary for the brushes and cache them. But this version of the loop takes 90 seconds!

Dictionary<ushort, Brush> brushes = new Dictionary<ushort,Brush>();
Brush brStroke = null;
for (uint index = 0; index < count; index++)
   {
   System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();

   path.Data = GetPathData();

   ushort gt = GetColorTableIndex(index);
   if (brushes.ContainsKey(gt))
      brStroke = brushes[gt];
   else
      {
      brStroke = new SolidColorBrush(GetColor(index));
      brushes.Add(gt, brStroke);
      }

   path.Stroke = brStroke;
   path.StrokeThickness = thickness;
   canvas.Children.Add(path);
   }

Why that?

Does anybody have an idea?

Thanks,

Thomas

 

update status and progress bar on popup from VM

$
0
0

I have a simple UserControl that has a textblock and a progress bar.  The textblock and bar are bound to some values in the ViewModel.

I have defined this control as a popup like this.

<Popup IsOpen="{Binding Path=ProgressShowing}" AllowsTransparency="True"
                   HorizontalOffset="0" VerticalOffset="0"
                   Placement="Center" PopupAnimation="Fade"
                   Width="385" Height="115"><popControl:PaymentFinishProgressView /></Popup>

My idea is to trigger the ProgressShowing to pop this little dialog up and then update the status and progress bar from the VM, while it is busy working on something. 

Problem is when I update things, I don't see anything.  Then the last second I see the popup flash on the screen and its gone.  I was thinking I need to either force a refresh or take a different route all together. I would prefer the former to the later as this is a very easy approach.  I am not sure how to use InteractionRequest to do something like this.

Thanks for your time.

DataGrid ScrollIntoView does not bring given item into view (when using virtualization and grouping)

$
0
0

Hi All,

I use the DataGrid from .Net Framework 4.5 with row and column virtualization enabled. If I select an item in the DataGrid, add grouping using the DataGrid GroupStyle property and then execute a ScrollIntoView for the selected item, the selected item is not brought into view. I need the selected item to be brought into view programatically after adding the grouping without any interaction from the user.

Steps to reproduce:
- compile the code provided and start the application
- select the item with FirstName equal to "FirstName0000000030"
- press button "Add group"
- groups appear but the selected item is not brought into view

Notes:
- the issue does not reproduce for all items in the grid (for some it does, for some it doesn't). On my machine it allways reproduces with the item "FirstName0000000030". If it does not reproduce please try also with other items.
- pressing the button "Scroll to selection" multiple times after the "Add group" is pressed it finally bring the selected element into view (this is not a desireable solution for us because it involve user interaction from the user)

XAML:

<Window x:Class="ScrollIntoViewBug.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local ="clr-namespace:ScrollIntoViewBug"
        Title="ScrollIntoView" WindowState="Maximized" Loaded="Window_Loaded"><Window.Resources><GroupStyle x:Key="GroupHeaderStyle"><GroupStyle.Panel><ItemsPanelTemplate><VirtualizingStackPanel Orientation="Vertical" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"/></ItemsPanelTemplate></GroupStyle.Panel><GroupStyle.ContainerStyle><Style TargetType="{x:Type GroupItem}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type GroupItem}"><Expander Name="groupExpander" IsExpanded="True"><Expander.Header><StackPanel Orientation="Horizontal"><TextBlock Text="{Binding Path=ItemCount}"/><TextBlock Text="Items"/></StackPanel></Expander.Header><ItemsPresenter></ItemsPresenter></Expander></ControlTemplate></Setter.Value></Setter></Style></GroupStyle.ContainerStyle></GroupStyle></Window.Resources><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*"></ColumnDefinition></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="30"></RowDefinition><RowDefinition Height="*"></RowDefinition></Grid.RowDefinitions><StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal"><Button Name="btnAddGrouping" Click="btnAddGrouping_Click" Margin="0,3,3,3">Add group</Button><Button Name="btnClearGrouping" Click="btnClearGrouping_Click" Margin="3">Clear group</Button><Button Name="btnScrollIntoView" Click="btnScrollIntoView_Click" Margin="3">Scroll to selection</Button></StackPanel><DataGrid Name="MyDataGrid" 
                  Grid.Row="1" Grid.Column="0"
                  EnableRowVirtualization="True"
                  EnableColumnVirtualization="True"
                  VirtualizingStackPanel.IsVirtualizing="True" 
                  VirtualizingPanel.IsVirtualizingWhenGrouping="True"
                  VirtualizingPanel.VirtualizationMode="Standard"></DataGrid></Grid></Window>

Code behind:

namespace ScrollIntoViewBug
{
    public enum Gender { Male, Female };
    public class Customer
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public Gender Gender { get; set; }
        public string Department { get; set; }
    }
    public partial class MainWindow : Window
    {
        CollectionViewSource cvSource;
        public MainWindow()
        {
            InitializeComponent();
        }
        private List<Customer> createRows()
        {
            System.Int64 rowNo = 100;
            System.Int64 noOfGroups = 80;
            // generate rows
            List<Customer> customers = new List<Customer>();
            for (System.Int64 i = 0; i < rowNo; i++)
            {
                Gender gender;
                if (i % 2 == 0)
                    gender = Gender.Male;
                else
                    gender = Gender.Female;
                string deparment = "Dept" + (i % noOfGroups + 1).ToString("D10");
                customers.Add(new Customer()
                {
                    FirstName = "FirstName" + (i + 1).ToString("D10"),
                    LastName = "LastName" + i.ToString("D10"),
                    Gender = gender,
                    Department = deparment
                });
            }
            return customers;
        }
        private ObservableCollection<DataGridColumn> createColumns()
        {
            System.Int64 colNo = 100;
            // generate columns
            ObservableCollection<DataGridColumn> columns = new ObservableCollection<DataGridColumn>();
            DataGridTextColumn textColumn = new DataGridTextColumn();
            textColumn.Header = "First Name";
            textColumn.Binding = new Binding("FirstName");
            columns.Add(textColumn);
            DataGridComboBoxColumn comboColumn = new DataGridComboBoxColumn();
            comboColumn.Header = "Gender";
            comboColumn.TextBinding = new Binding("Gender");
            comboColumn.ItemsSource = typeof(Gender).GetEnumValues();
            columns.Add(comboColumn);
            DataGridTextColumn depColumn = new DataGridTextColumn();
            depColumn.Header = "Department";
            depColumn.Binding = new Binding("Department");
            columns.Add(depColumn);
            for (System.Int64 i = 2; i < colNo; i++)
            {
                textColumn = new DataGridTextColumn();
                textColumn.Header = "Last Name" + (i + 1).ToString("D10");
                textColumn.Binding = new Binding("LastName");
                columns.Add(textColumn);
            }
            return columns;
        }
        private void loadGridData()
        {
            // add columns
            ObservableCollection<DataGridColumn> columns = createColumns();
            foreach (DataGridColumn col in columns)
                MyDataGrid.Columns.Add(col);
            // add rows
            cvSource = new CollectionViewSource();
            cvSource.Source = createRows();
            // set datagrid items
            Binding itemsSourceBinding = new Binding();
            itemsSourceBinding.Source = cvSource;
            MyDataGrid.SetBinding(DataGrid.ItemsSourceProperty, itemsSourceBinding);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loadGridData();
        }
        private void btnAddGrouping_Click(object sender, RoutedEventArgs e)
        {
            ICollectionView view = CollectionViewSource.GetDefaultView(MyDataGrid.ItemsSource);
            if (view == null)
                return;
            view.GroupDescriptions.Add(new PropertyGroupDescription("Department"));
            if (MyDataGrid.GroupStyle == null || MyDataGrid.GroupStyle.Count == 0)
            {
                GroupStyle groupStyle = TryFindResource("GroupHeaderStyle") as GroupStyle;
                if (groupStyle != null)
                {
                    if (groupStyle.ContainerStyle != null)
                        groupStyle.ContainerStyle.Seal();
                    MyDataGrid.GroupStyle.Add(groupStyle);
                }
            }
            ScrollToSelection();
        }
        private void ScrollToSelection()
        {
            MyDataGrid.Focus();
            MyDataGrid.Items.MoveCurrentTo(MyDataGrid.SelectedItem);
            MyDataGrid.ScrollIntoView(MyDataGrid.SelectedItem);
        }
        private void btnClearGrouping_Click(object sender, RoutedEventArgs e)
        {
            ICollectionView view = CollectionViewSource.GetDefaultView(MyDataGrid.ItemsSource);
            if (view == null)
                return;
            view.GroupDescriptions.Clear();
            ScrollToSelection();
        }
        private void btnScrollIntoView_Click(object sender, RoutedEventArgs e)
        {
            ScrollToSelection();
        }
    }
}

Do I use correctly the ScrollIntoView in the code example?
Is there a way to programmaticaly scroll to the selected item imediatly after adding the grouping?
Is this a bug in the DataGrid from .Net Framework 4.5 related to ScrollIntoView?


WPF Window control with UserControl

$
0
0
I have one window control and I added one usercontrol in that. Now I want to access windows stackpanel visiblity true on button click of usercontrol button how it will possible can any one help me

Shivendra Bokade

autoclose menuitem list

$
0
0

Hi All.

I have MenuItem with radiobutton list. I would like when user will select one of radiobutton that menuitem list automatically close. How it to do?

Thanks.

Unhandled exception in XAML

$
0
0

I have a message that says I have a argumentexception in my xaml. I have included a picture below.


chuckdawit

Creating geometry for Viewport3D using Multitasking?

$
0
0

Hi,

I'm trying to populate a Viewport3D with UIElement3D objects. Because there is no DataBinding and Templating available with the Viewport3D, I do this manually using code.

First, I create a PointCollection3D for each UIElement3D which is my VertexBuffer for the 3d geometry. (I cannot use an IndexBuffer because it does not support "flat shading" without smoothed normals for some reason!) The vertex buffer contains the vertices that are generated by the triangulation algorithm.

Then, I create my MeshGeometry3D and a GeometryModel3D which is finally used by the resulting ModelUIElement3D.

This takes a very long time or big models, so I need to do this in background! But this is not working because (1) I cannot create WPF objects like PointCollection3D in another thread, and (2) I cannot access objects that have been created in the UI Thread from another thread.

I can't even do the actual triangulation of my 3d objects in a seperate thread. The triangulation process returns a number of Point3D which have to be added to the PointCollection3D in the UI Thread. Using a BlockingCollection in the seperate thread and converting into a PointCollection3D in the UI Thread is not an option for performance reasons.

Which options do I have left? Is there another way to create 3d geometry in another thread and include it into the Viewport3D in the UIThread? What would you suggest?

Best regards
Christian


How to display a text value in the designer but also do a binding?????

$
0
0

Hello,

When I define a textbox in my XAML, the designer will display the text as long as the Text property has a value:

<TextBlock Text="MyValue" /> 

But if I use a binding for the Text value, the designer does not show anything (I guess because it does not know what value to display). 

<TextBlock Text="{Binding Path=Value}" />

When I am trying to layout the GUI, it is pretty important to know where all the controls visually are and if the TextBlock is not visible, then you lose track of it.  Is there a way to set the text value via a binding but still have the designer visually indicate that a TextBlock component is located there?

Thanks for any insight - Peter Len

SHARING a DependencyProperty, really???

$
0
0

Hi guys,

i am new to WPF and i am still learning but is this really possible?

I found this blog about sharing dependency property between two different classes.

Does dependencyproperty system allow me to share a property with whoever i want?

This is the link of the blog post that explains how to share dependency properties:

http://csharpsimplified.wordpress.com/2009/02/10/shared-dependency-property/

WPF UI Virtualization

$
0
0

I am very new to WPF so please excuse me if the question seems naive. My objective is to create a WPF 'form' dynamically which contains only pairs of labels and combo boxes depending on the number of items being supplied to me. I am currently thinking of using a control which enables UI virtualization such as an items control and defining each individual item as a pair of label and combo boxes.

Question 1: Will a control virtualize a custom item containing a label and combo box by default or do I need to implement this virtualization myself?

Question 2: Either way, which is the best control to use for virtualization in this scenario?

I tried using an ListView/ListBox but that has a feature to highlight all items by default on mouse over which is undesirable.

The criteria for this is speed. I should ideally load only those labels and combo boxes that the user is currently scrolling through. Do I need to implement my own virtualization for this or can lists with custom items be virtualized by WPF? My custom item here is a pair of label and combo box together.

Thanks

Flow Right to Left Sub Menu opens to wrong direction - only in VS 2012

$
0
0

This code works prefect on Visual studio 2010

on Visual Studio 2012 the Sub Menu Aligns to the wrong side (as in LTR and not as it should be on RTL)

<Window x:Class="menutest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" FlowDirection="RightToLeft"><DockPanel><Menu DockPanel.Dock="Top"  HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="100"><MenuItem Header="בדיקה"><MenuItem Header="בדיקה ארוכה מאוד"></MenuItem><MenuItem Header="בדיקה ארוכה מאוד"></MenuItem><MenuItem Header="בדיקה ארוכה מאוד"></MenuItem></MenuItem></Menu></DockPanel></Window>


<window flowdirection="RightToLeft" height="350" title="MainWindow" width="525" x:class="menutest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><dockpanel><menu dockpanel.dock="Top" height="40" horizontalalignment="Left" verticalalignment="Top" width="100"><menuitem header="בדיקה"><menuitem header="בדיקה ארוכה מאוד"></menuitem><menuitem header="בדיקה ארוכה מאוד"></menuitem><menuitem header="בדיקה ארוכה מאוד"></menuitem></menuitem> </menu></dockpanel> </window>

Speech Recognition

$
0
0

I have developed a simple application using Microsoft's speech recognition which does the following

Recognizes a letter B and shows the command line argument on a message box

When I try to run it normally in Visual studio, it works very well. However, when I try to run the application file (.exe), it throws an exception as follows:

Chinmay

Navigation_from_Frame_on_Window

$
0
0

Hi there, 

Anyone knows some good tutorial about Navigation UserInterface through one frame hosted in a Window pls?

WPF Datepicker MVVM Light passing selected date to viewmodel

$
0
0

I'm new to this and I'm at my wits end so I'm reaching out for help.

I'm trying to pass the selected dates to a property that I can then use in a sql query, but the dates past are the default and the the newly selected dates. Below is my xaml, viewmodel and sqlquery class. Any help would be greatly appreciated.

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding Main, Source={StaticResource Locator}}"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="NSP_Commission.MainWindow"
        Title="NSP Commission Tracker" Height="350" Width="525"><Grid><Grid.RowDefinitions><RowDefinition Height="40"/><RowDefinition Height="*"/></Grid.RowDefinitions><Label Margin="5,5,6.103,9" HorizontalAlignment="Left" Width="110" Content="Select Date Range:"/><DatePicker x:Name="dpBeginDate" HorizontalAlignment="Left" Margin="120,5,0,9" Width="120" SelectedDate="{Binding BeginDate, Mode=TwoWay}"/><DatePicker x:Name="dpEndDate" HorizontalAlignment="Left" Margin="270,5,0,9" Width="120" SelectedDate="{Binding EndDate, Mode=TwoWay}"/><TextBox Text="To" HorizontalAlignment="Left" Margin="242,6,0,10" Width="28" BorderBrush="{x:Null}"/><Button x:Name="ImportButton" Content="Import" HorizontalAlignment="Right" Margin="0,8,5,10" Width="75" d:LayoutOverrides="Height" Command="{Binding ImportData}"/></Grid></Window>

namespace NSP_Commission.ViewModel
{

    public class MainViewModel : ViewModelBase
    {
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                ImportData = new RelayCommand(() => ImportDataExecute(), () => true);   
            }   
        }

        public ICommand ImportData { get; private set; }
        private void ImportDataExecute()
        {
            Invoice_Hdr ih = new Invoice_Hdr();
            ih.LoadInvoice_Hdr();
            Invoice_Dtl id = new Invoice_Dtl();
            id.LoadInvoice_Dtl();

            MessageBox.Show("Import Complete!");
        }

        private DateTime _beginDate = DateTime.Today;
        public DateTime BeginDate
        {
            get { return _beginDate; }
            set
            {
                _beginDate = value;
                RaisePropertyChanged("BeginDate");
            }
        }

        private DateTime _endDate = DateTime.Today;
        public DateTime EndDate
        {
            get { return _endDate; }
            set
            {
                _endDate = value;
                RaisePropertyChanged("EndDate");
            }
        }
    }   
}

namespace NSP_Commission.CustomCode.SqlQuerys
{
    class Invoice_Hdr : MainViewModel
    {
        public string LoadInvoice_Hdr()
        {
            string myqueryString;
            DateTime myBeginDate;
            DateTime myEndDate;

            //Assign Report Parameters Based on Logged In User
            //SelectedDates sd = new SelectedDates();
            
            myBeginDate = BeginDate;
            myEndDate = EndDate;

            myqueryString = "blah blah " + BeginDate + ";

            return myqueryString;
        }
    }
}

Indeterminate ProgressBar inside ListBox ItemTemplate does not displayed in WPF. Bug?

$
0
0

Indeterminate ProgressBar inside ListBox ItemTemplate does not displayed in WPF. Bug?

Currently using Framework 4.0

<ListBox ItemsSource="{Binding FileDownloads}" HorizontalAlignment="Stretch">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Background="Red" HorizontalAlignment="Stretch" >
                            <ProgressBar Panel.ZIndex="100" Visibility="Visible" x:Name="ProgressBar" Minimum="0" Maximum="100"  IsIndeterminate="True" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>



Generic WeakEvent Manager & Listener

$
0
0
thought it will be useful,
 
you can use it like this:
 
 
 lsnr = new GenericWeakEventListener<MyControl>(Handler);
 GenericWeakEventManager<MyControl>.AddListener(MyControl.ClickEvent, _mc, lsnr);privatevoid Handler(object sender, RoutedEventArgs e)
 {
 Debug.WriteLine("Clicked!");
 }
 

which is like doing
 
_mc.Click += Handler
 
Just that it prevents the memory leak by using microsoft weak event pattern
 
when you make your controls
 
without you needing to implement one of your own

for other routed events in to control create another listener like this:
lsnr2 = new GenericWeakEventListener<MyControl>(Handler2);

GenericWeakEventManager<MyControl>.AddListener(MyControl.Click2Event, _mc, lsnr2);
 which is like:
_mc.Click2 += Handler2;
|
|
|
here is the code:
using System;using System.Diagnostics;using System.Windows;namespace MyApp.WeakEvent
{publicclass GenericWeakEventListener<T> : IWeakEventListener, IDisposablewhere T : FrameworkElement
 {public GenericWeakEventListener(RoutedEventHandler handler)
 {
  _handler = handler;
 }private RoutedEventHandler _handler;publicbool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
 {var re = (RoutedEventArgs)e;if (managerType == typeof(GenericWeakEventManager<T>) && (re.RoutedEvent == _e))
  {
  OnEvent(sender, re);returntrue;
  }returnfalse;
 }privatebool _isInit = false;publicvoid Init(RoutedEvent e, T t)
 {if (_isInit)thrownew InvalidOperationException("create another instance of the listener");

  _e = e;
  _t = new WeakReference(t);

  _isInit = true;
 }private RoutedEvent _e;private WeakReference _t;privatevoid OnEvent(object sender, RoutedEventArgs e)
 {if (_handler != null)
  {
  _handler(sender, e);
  }
 }privatebool _disposed = false;

 ~GenericWeakEventListener()
 {
  Dispose(false);#if DEBUG
  Debug.WriteLine("GC Deleted: GenericWeakEventListener<"+ typeof(T).Name + ">");#endif
 }publicvoid Dispose()
 {
  Dispose(true);
  GC.SuppressFinalize(this);
 }privatevoid Dispose(bool disposing)
 {if (!_disposed && disposing && _t.IsAlive)
  {
  GenericWeakEventManager<T>.RemoveListener(_e, (T)_t.Target, (IWeakEventListener)this);#if DEBUG
  Debug.WriteLine("Disposing: GenericWeakEventListener<"+ typeof(T).Name + ">");#endif
  }

  _handler = null;
  _e = null;
  _t = null;

  _disposed = true;
 }
 }publicclass GenericWeakEventManager<T> : WeakEventManagerwhere T : FrameworkElement //can also be Control
 {private GenericWeakEventManager(RoutedEvent e)
 {if (e.OwnerType != typeof(T))thrownew InvalidOperationException("event doesn't exists in T");

  _event = e;
 }

 privatereadonly RoutedEvent _event;publicstaticvoid AddListener(RoutedEvent e, DependencyObject source, GenericWeakEventListener<T> listener)
 {
  listener.Init(e, (T)source);
  AddListener(e, source, (IWeakEventListener)listener);
 }publicstaticvoid RemoveListener(RoutedEvent e, DependencyObject source, GenericWeakEventListener<T> listener)
 {
  listener.Dispose();
 }publicstaticvoid AddListener(RoutedEvent e, DependencyObject source, IWeakEventListener listener)
 {lock (_lock)
  {
  GetCurrentManager(e);
  AddListener(source, listener);
  }
 }publicstaticvoid RemoveListener(RoutedEvent e, DependencyObject source, IWeakEventListener listener)
 {lock (_lock)
  {
  GetCurrentManager(e);
  RemoveListener(source, listener);
  }
 }///<summary>/// Add a listener to the given source's event.///</summary>privatestaticvoid AddListener(DependencyObject source, IWeakEventListener listener)
 {if (source == null)thrownew ArgumentNullException("source");if (listener == null)thrownew ArgumentNullException("listener");

  CurrentManager.ProtectedAddListener(source, listener);
 }

 ///<summary>/// Remove a listener to the given source's event. /// no need to call, only implement the opposite of add, and it will be called automatically when needed///</summary>privatestaticvoid RemoveListener(DependencyObject source, IWeakEventListener listener)
 {if (source == null)thrownew ArgumentNullException("source");if (listener == null)thrownew ArgumentNullException("listener");

  CurrentManager.ProtectedRemoveListener(source, listener);
 }



 ///<summary>/// Listen to the given source for the event.///</summary>protectedoverridevoid StartListening(object source)
 {var fe = source as T;if (fe != null)
  fe.AddHandler(_event, (RoutedEventHandler)DeliverEvent);
 }///<summary>/// Stop listening to the given source for the event.///</summary>protectedoverridevoid StopListening(object source)
 {var fe = source as T;if (fe != null)
  fe.RemoveHandler(_event, (RoutedEventHandler)DeliverEvent);
 }// get the event manager for the current thread & eventprivatestatic GenericWeakEventManager<T> CurrentManager
 {get
  {
  SetCurrentManager(typeof(GenericWeakEventManager<T>), _mgr);//ensure it's therereturn _mgr;
  }set
  {
  _mgr = value;
  SetCurrentManager(typeof(GenericWeakEventManager<T>), _mgr);
  }
 }privatestatic GenericWeakEventManager<T> _mgr = null;privatestaticreadonlyobject _lock = newobject();privatestatic WeakEventManager GetCurrentManager(RoutedEvent e)
 {
  Dictionary<RoutedEvent, GenericWeakEventManager<T>> d;
  GenericWeakEventManager<T> m;if (_dic.TryGetValue(typeof(T), out d))
  {if (!d.TryGetValue(e, out m))
  {
   m = new GenericWeakEventManager<T>(e);
   d.Add(e, m);
  }
  }else
  {
  d = new Dictionary<RoutedEvent, GenericWeakEventManager<T>>();
  m = new GenericWeakEventManager<T>(e);

  d.Add(e, m);
  _dic.Add(typeof(T), d);
  }

  CurrentManager = m;
  return m;
 }privatestaticreadonly Dictionary<Type, Dictionary<RoutedEvent, GenericWeakEventManager<T>>> _dic = new Dictionary<Type, Dictionary<RoutedEvent, GenericWeakEventManager<T>>>();

 }
}



Tutorial to create application to query Active Directory

$
0
0

Hi, 

I am completely new to Visual Studio and WPF and i want to learn a little bit.

Is there a detailed tutorial where i can learn how to create a simple application which query Active Directory?

Something like enter the username and return The AD Groups that the user belongs to.

Thanks

Creating a dynamically 3D model in XAML

$
0
0

Hello all.<o:p></o:p>

I would like to ask some advice
about how to create dynamically 3D models using XAML and C#.<o:p></o:p>

Basically the program will
import two .dxf files(Autocad). It will extract the coordinates of a
semi-polyhedron  from one, and angle orientations and coordinates from the
other. I am saying semi-polyhedron because the coordinates will not completely
define it. It will need the information from the second.dxf file in order to
complete the solid. Therefore, I will have to calculate the equation of planes
using the information of the second .dxf and intersect them with coordinates of
the first .dxf file. I know it looks confusing , ant it is. <o:p></o:p>

I will have to render both the
coordinates and the planes, and let the user move the planes to fit in the
coordinates finally defining the polyhedron in the screen. This is only the
first step of the process and I will stop here for now so things don't turn
even more complex.<o:p></o:p>

Any suggestions will be very
much appreciated. If the description is not clear please do not hesitate to ask
any question you might have.<o:p></o:p>

I saw an old post but it didn't
helped much http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a2aef4db-d2d8-40ac-a61a-5e2ba64cfb57/<o:p></o:p>



Jair Santos

UserControl with a TextBox inside: how to fire the ErrorTemplate of the TextBox instead of the UserControl's one.

$
0
0

I created a UserControl wich has a TextBox inside. The value of the "Text" property of che UserControl (bound, of course, with the TextBox) is validated, but when it has errors I see the ErrorTemplate of che UserContol instead of the ErrorTemplate of the TextBox.

How can I do to "notify" the validation error to the TextBox, so I can see its ErrorTemplate?

Hope you can help me, I'm going mad with this...

Francesco

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>