The Wayback Machine - https://web.archive.org/web/20090217131428/http://www.codeproject.com:80/script/Forums/View.aspx?fid=1004114
Click here to Skip to main content
5,896,359 members and growing! (18,955 online)
Announcements
* Bold indicates new messages since 3:14 17 Feb '09




BullFrog Power
Advanced Search
Sitemap

WPF / WCF / WF


Home > Forums > WPF / WCF / WF

 Msgs 1 to 25 of 1,061 (Total in Forum: 3,730) (Refresh)FirstPrevNext
QuestionI have two [ApplicationCommands.New] in my windowmemberFeras Mazen Taleb1 hr 47mins ago 
Sorry I know that my question is very easy
How can I use two ApplicationCommands.New
in my form

okaay I have to give different name for each one but it didn't work .
but the Key Crtl+N for any command ??

You have To Search About The Truth Of Your Life
Why Are you Here In Life ?

QuestionWPF application using MVP(model view presenter) design patternmemberMember 40091022hrs 26mins ago 
Hi,

I am trying to create a WPF application using MVP pattern. The user of the application should be able to create customers and edit customer information. The data is stored in the SQL database at the backend.

Can any one help me by providing information regarding MVP pattern and how we can implement the same with WPF application.

Thanks in advance.

Best regards,
Sarvani
AnswerRe: WPF application using MVP(model view presenter) design patternmvpPete O'Hanlon2hrs 23mins ago 
Rather than use the MVP pattern directly, there's a variation called MVVM. Josh Smith has recently had an article published in MSDN magazine[^] on how to do MVVM in WPF - it's a must read.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



QuestionUpdating only visible rows in WPF ListViewmemberPankaj C4hrs 31mins ago 
I am using a GridView inside the WPF ListView control. On display of data I perform some validations and change color of some cells in each row accordingly. The problem is that there can be thousands of such rows in the ListView (bound to an observable collection)which leads to high CPU utilization.

Is there a way that i can update only the visible rows in the listview. And as I scroll the listview down the next set of rows start getting updated.. This way the CPU utilization would be kept in check inspite of thousands of rows being updated in the observable collection..

Any help is appreciated.

Thanks.

Pankaj Chamria,
Software Programmer.

AnswerRe: Updating only visible rows in WPF ListViewmvpPete O'Hanlon1 hr 38mins ago 
I would use a VirtualizingStackPanel on the listview. This is an attached property, that is used like this:
<ListBox VirtualizingStackPanel.IsVirtualizing = "True" ItemsSource="{Binding MySource}" ItemsTemplate="{Binding MyTemplate}" /<


"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



QuestionWPF, Delegates, The calling thread cannot access this object because a different thread owns itmemberfrosty_4th10hrs 14mins ago 
Help,

I'm at my wits end. I have been working for days trying to execute the simplest task. Here is the basics of my WPF project.

I have a main form.
I have a Dialog.
I have a class module that handles serial comm

When I receive data on the serial line, I want to launch the dialog. My main form has an instance of my dialog. My main form also contains an instance of my serial comm class. When instantiating my comm class I pass a delegate sub to be called when data arrives on the serial port. So far so good.

The sub gets called when data arrives on the port, but when I try to launch my dialog I get the message "The calling thread cannot access this object because a different thread owns it".

What am I missing here? I have tried instantiating the dialog within the serial comm module but get the error that the instantiation must happen from an STA thread.

I have been googling for days, but each delegate example is different than the next. I'm not even sure that the delegate handling is my problem.

I apologize if this seems like a simple question, I am new to WPF and do not yet know what I don't know. None of the books I've purchased seem to go into any detail regarding my particular situation.

Thank You
AnswerRe: WPF, Delegates, The calling thread cannot access this object because a different thread owns itmemberABitSmart9hrs 38mins ago 
frosty_4th wrote:
"The calling thread cannot access this object because a different thread owns it"

You are trying to access the UI from a non-UI thread.

In WPF, you need to use the Dispatcher for cross-thread UI interactions.MSDN[^]

e.g.,
public void Test()
{
Button theButton = button1 as Button;

if (theButton != null)
{
// Checking if this thread has access to the object.
if (theButton.Dispatcher.CheckAccess())
{
// This thread has access so it can update the UI thread.
theButton.Content = "Hello";
}
else
{
// This thread does not have access to the UI thread.
// Place the update method on the Dispatcher of the UI thread.
theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(Action)(() => { theButton.Content = "Hello"; }));
}
}
}

GeneralRe: WPF, Delegates, The calling thread cannot access this object because a different thread owns itmvpPete O'Hanlon3hrs 49mins ago 
Sacha Barber proposed a fantastic extension method that you might want to look into. It's called InvokeIfRequired, and looks a bit like this:
public static void InvokeIfRequired(this DispatcherControl control, Action operation)
{
if (control.Dispatcher.CheckAccess())
{
operation();
}
else
{
control.Dispatcher.BeginInvoke(DispatcherPriority.Normal, operation);
}
}
Then, it's simple to do:
Dispatcher.CurrentDispatcher.InvokeIfRequired(()=>{ theButton.Content="Hello"; });


"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



GeneralRe: WPF, Delegates, The calling thread cannot access this object because a different thread owns itmemberfrosty_4th2hrs 33mins ago 
Thanks Pete !
GeneralRe: WPF, Delegates, The calling thread cannot access this object because a different thread owns itmvpPete O'Hanlon2hrs 25mins ago 
You're welcome.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



QuestionBinding User Controlsmemberhb5213421413hrs 7mins ago 
I am having some issues binding data in a user control and am hoping that someone can help. Basically, I am attempting to include a User Control in another control and directly link the contents of a list, though I can't seem to get the binding correct. I don't have the same trouble with ACtrl because it is loaded through a DataTemplate within a ContentControl. In the case of BCtrl, I know the type, so I'd rather simplify the XAML with the direct reference. Is this possible? In the code below, the '?????' highlight where I think I need to declare the binding and a guess of what I should be putting there. Thanks in advance!

//
// CONTROL 1
// XAML:
//







//
// C#:
partial class ACtrl : UserControl {

}




//
// CONTROL 2
// XAML:
//







//
// C#:
partial class BCtrl : UserControl {

}



//
// Data Class
// C#:
//
Class A : DependencyObject {
public static readonly DependecnyProperty string Description = ...
public static readonly DependencyProperty ObservableList<object> AItems = ...
...
} </object>
AnswerRe: Binding User Controlsmemberhb5213421413hrs 5mins ago 
Oops, the < and > were a bit messed up... Hopefully this works.

//
// CONTROL 1
// XAML:
//
<UserControl x:Class="ACtrl" ...>
<StackPanel>
<TextBlock Text="{Binding Description}" />
<local:BCtrl ???????="{Binding AItems}" />
</StackPanel>
</UserControl>

//
// C#:
partial class ACtrl : UserControl {

}


//
// CONTROL 2
// XAML:
//
<UserControl x:Class="BCtrl" ...>
<Grid>
<ListView ItemsSource="{Binding}" >
</Grid>
</UserControl>


//
// C#:
partial class BCtrl : UserControl {

}



//
// Data Class
// C#:
//
Class A : DependencyObject {
DependecnyProperty string Description = ...
DependencyProperty ObservableList<object> AItems = ...
...
}
GeneralRe: Binding User ControlsmemberABitSmart10hrs 7mins ago 
You could set the DataContext property
<local:BCtrl DataContext="{Binding AItems}" />

You also need to set an ItemTemplate for the ListView to display the databound object.
e.g.
<ListView.ItemTemplate>
   <DataTemplate >
         <TextBlock x:Name="element" HorizontalAlignment="Center" Text="{Binding dummyPropInTheDataBoundObject}"></TextBlock >
   </DataTemplate>
</ListView.ItemTemplate>
GeneralRe: Binding User Controlsmemberhb521342148hrs 48mins ago 
Thanks a bunch
QuestionProblem with DataGrid (selected rows)memberCzechtim213hrs 39mins ago 
I have problem with selected rows in DataGrid from WPF Toolkit. I have Observable Collection as ItemsSource.

I created small sample application. I´m adding file adresses to DataGrid and when I click on row in DataGrid I´m testing existence of file. If file doesn´t exit I remove that selected row automatically from DataGrid (ObservableCollection).

Problem is, that sometimes after deleting a row from DataGrid, previously selected row still remains as selected (blue background of row). But that row isn´t selected, because when I click on buton „Delete selected row“ I recieve message that no row is selected.

Exactly: When I have in DataGrid selected row (x) and a click on row (x + 1) and file doesn´t exit at row (x + 1), that row (x + 1) is automatically deleted and no row is selected - everything´s all right.

But when I have selected row (x) and a click on row (x - 1) and file doesn´t exit at row (x - 1), that row (x - 1) is deleted but row (x) still remains as selected (blue background of row x) - PROBLEM.

Doessomebody know please how to solve it? I need to have all rows visually unselected every time in my application after deleting a row in DataGrid (white background of all rows).

Here´s my code:

Window1.xaml
<Window x:Class="DataGrid.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="9*" />
</Grid.RowDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<Grid.ColumnDefinitions>

</Grid.ColumnDefinitions>

<dg:DataGrid x:Name="dataGrid"
Grid.Row="3"
Grid.ColumnSpan="2"
SelectionChanged="dataGrid_SelectionChanged"
Grid.Column="0"
CanUserDeleteRows="True"
Loaded="dataGrid_Loaded"
IsReadOnly="True"
SelectionUnit="FullRow"
SelectionMode="Single"
CanUserAddRows="False"
Visibility="Visible"
Margin="1"
Background="White"
AlternationCount="2" />
<TextBox Name="textBox1" Grid.Row="0" Grid.ColumnSpan="2" />
<Button Grid.Row="1" Name="Add" Click="Add_Click">Add address to DataGrid</Button>
<Button Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Name="Delete" VerticalAlignment="Top" Click="Delete_Click">Delete selected row</Button>
</Grid>
</Window>


Window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.IO;
using System.Collections.ObjectModel;

namespace DataGrid
{
public partial class Window1 : Window
{

ObservableCollection obs_col;
public Window1()
{
InitializeComponent();
obs_col = new ObservableCollection();
}


private void dataGrid_Loaded(object sender, RoutedEventArgs e)
{
dataGrid.ItemsSource = obs_col;
}


private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Files selectedFile = (Files)dataGrid.SelectedItem;

if (selectedFile != null)
{
if (!File.Exists(selectedFile.File))
{
obs_col.RemoveAt(obs_col.IndexOf(selectedFile));
}
}
}


private void Add_Click(object sender, RoutedEventArgs e)
{
obs_col.Add(new Files(textBox1.Text));
}


private void Delete_Click(object sender, RoutedEventArgs e)
{
Files selectedFile = (Files)dataGrid.SelectedItem;

if (selectedFile != null)
{
obs_col.RemoveAt(obs_col.IndexOf(selectedFile));
}
else
MessageBox.Show("No row is selected");
}
}
}


Files.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataGrid
{
class Files
{

public string File
{
get; set;
}

public Files(string file)
{
this.File = file;
}

}
}

QuestionUsing WCF from COM applicationmemberbajschaap17hrs 12mins ago 
Hi all,
I have made a COM vissible class which I want to call from a COM application (VB6 and VBA MS-Access). It compiles to a file called UniCom.dll. The UniCom.dll class uses WCF to communicate with a webservice. When used from a VB.NET program everything works fine, the configuration is automatically read from the app.config file. The problem is how can I set this up so that it works when called from a VB6 application? UniCom.dll is registered and can be called from VB6 but when I want to use a method I made in UniCom.dll which uses WCF, I get an error indicating there is no system.servicemodel section in the config file, which is pretty obvious since a VB6 app does not have a config file.
I tried to put a UniCom.dll.config in the directory of the calling VB6 app, and I tried to put UniCom.dll.config in the same directory where UniCom.dll is installed. This does not work. Any suggestions how to resolve this problem?
AnswerRe: Using WCF from COM applicationmvpMark Salsbery16hrs 24mins ago 
Two possible solutions I know of:

1) Programmatically configure the service channels/endpoints.
A server-side example is here[^]. The code is similar for a client.

2) Process a configuration file yourself, something like here:
Loading the WCF configuration from different files on the client side[^]

Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java

GeneralRe: Using WCF from COM applicationmemberbajschaap3hrs 49mins ago 
Hi Mark, thanks for your answer. It still looks fairly complicated to me.
Is there perhaps a way to simply tell UniCom.dll to use a specific config file at a certain location? If that is possible than the solution would be a property in UniCom.dll by which the calling app (VB6 / MS-Access) can point to a config file.

Cheers Bart
Question[Message Deleted]memberPrajeesh23:26 15 Feb '09  

AnswerRe: WPFmvpPete O'Hanlon23:32 15 Feb '09  
Please - just post one question. You could have asked both of these questions in one go, so there was no need to post the other one.

WPF - or Windows Presentation Foundation, is the evolution of desktop applications. It is designed to go beyond what you can do with traditional WinForms, and isn't bound by limitations of GDI+, building on DirectX as it does.

Silverlight is a cross-platform, web browser based version of WPF. Because it's cross platform, certain of the more powerful features of WPF (such as 3D) are not present yet, but it's getting there. BTW - with Silverlight, you can run .NET applications inside your browser.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



Question[Message Deleted]memberPrajeesh23:38 15 Feb '09  

AnswerRe: Languages in WPFmvpPete O'Hanlon0:18 16 Feb '09  
I'm curious as to why you posted a question here asking this, rather than doing a simple Google search for the answer. It will have taken you longer to type this in, and wait for a reply from me than it would for you to search for it yourself. Please - if you are serious about being a development professional - learn to use basic research tools, such as Google, for yourself.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



GeneralMessages in limbomvpLuc Pattyn22hrs 41mins ago 
How is it anything you reply to gets deleted, are you using a magic browser, a cloaking device, a secret tag, to that effect?

Smile

<removable=false>

Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


GeneralRe: Messages in limbomvpPete O'Hanlon20hrs 58mins ago 
Luc Pattyn wrote:
How is it anything you reply to gets deleted, are you using a magic browser, a cloaking device, a secret tag, to that effect?


I'm just lucky that way - and I see you found the tag to prevent me removing your message.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



General[Message Deleted]mvpMark Salsbery18hrs 21mins ago 

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Last Updated 9 Aug 2007
Web19 | Advertise | Privacy
Copyright © CodeProject, 1999-2009
All Rights Reserved. Terms of Use