|
You may have only one lock instruction, but there is another lock.
The Invoke itself is a kind of lock. It will wait until the action finishes. That's why it dead-locks (and the BeginInvoke does not, as it does not wait).
|
|
|
|
|
Hi
Regarding my service class attribute, [EnableClientAccess(RequiresSecureEndpoint = true)], I was wondering if it was possible to change the value of RequiresSecureEndpoint based on a value I can set in the config file. e.g.
<appSettings>
<add key="RequireSSL" value="True" />
</appSettings>
Thanks
|
|
|
|
|
I have the following set-up:
1. ViewModel:
...
public ICommand LoadSomeViewCommand;
public SomeViewModel(IRegionManager regionManager, IUnityContainer container)
{
this._regionManager = regioinManager;
this._container = container;
LoadCommand = new RelayCommand(new Action<object>(LoadSomeViewExecute), new Predicate<object>(CanLoadExecute));
}
...
private void LoadSomeViewExecute(object obj)
{
IRegion mainRegion = _regionManager.Regions[RegionNames.MainRegion];
foreach (var v in mainRegion.Views)
{
mainRegion.Remove(v);
}
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(SomeNewView));
}
private bool CanLoadExecute(object obj)
{
return true;
}
in the View.cs:
public SomeView(IRegionManager regionManager, IUnityContainer container)
{
InitializeComponent();
this.DataContext = new SomeViewModel(regionManager, container);
}
public SomeViewModel ViewModel
{
get { return (SomeViewModel)this.DataContext; }
}
and in xaml:
...
<StackPanel grid.Row="2">
<Button Content="Load"
Command="{Binding LoadCommand}"/>
...
</StackPanel>
When I click the button to load another component, the LoadCommand has been set in the constructor but never seems to be called on the button click.
I have been converting a VB project to C# to try and learn the language and maybe I have missed something in the translation.
I have other containers injecting into the shell that don't use Command calls that are working fine.
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Dunno if you want these kinds of comments, so feel free to ignore them if you are offended , but your question IS answered below.
1) Bad practice to litter your code with 'this'. It's not needed as its implied.
2) Bad practice to use an interface to reference a concrete class inside of the class itself (public ICommand LoadSomeViewCommand)... its a RelayCommand, not an ICommand. You should only pass it around externally as an ICommand.
3) Your implementation of RelayCommand isn't correct. You should not need all that new Action, new Predicate garbage.
4) Your non-generic RelayCommand should not take any params. RelayCommand<T> is the one that takes a param and that one should be type safe. Don't pass in an object, pass in the real type.
5) *THE ANSWER TO YOUR QUESTION* You can't databind to a variable. Only properties.
6) If you are using UnityContainer, or any other DI container. USE IT. In your SomeView contructor, you have the unity container reference, but aren't using it to create the object.
7) Better to use an attached property to set your data context, so you get rid of all the hand wiring with a code behind.
8) Stop using var's for simple types. This isn't JavaScript . Vars have specific uses, this isn't one of them.
|
|
|
|
|
Cheers, i am not easily offended and want to learn this the correct way - very hard without someone to bounce off. As I said, this is from a VB project I am converting to try nd get the hang of the language.
You have given me a few things to work on,and probably learn from.
Thanks
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
SledgeHammer01 wrote: 1) Bad practice to litter your code with 'this'. It's not needed as its implied.
One of the default rules in FXCop or style cop or some such horror dictates the use of this. EVERYWHERE, I do find it useful for limiting the scope of intellisense but it really feels like using the VB me. which I still cringe at!
Oh and if I remember correctly Andy is a Kiwi living in Oz, the bugger has to have a thick skin and anyone using VB grows one naturally!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Andy is a Kiwi living in Oz, the bugger has to have a thick skin
Yes, and I know Mick Martin to drink with!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Andy_L_J wrote: I know Mick Martin to drink with
Having not yet had this experience and only dealt with his pleasantly abrasive online personality I do look forward to the opportunity when I next hit Sydney. As I now visit Cairns instead I don't know when this will happen though.
I have an ebook (somewhere) I used when moving from VB to C#, it helped with the syntax differences, let me know if you are interested.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sometimes I'll type "this" if I don't remember the prop name, but I'll delete the this afterwards. I use a leading underscore (which Andy did) on class member variables. That differentiates member variables from local variables. I think very few people agree on formatting / style issues . In my last job, my team lead insisted everybody format the code with 3 spaces. It took me a while to convince him that nobody else likes 3 spaces and if he went to tabs, then everybody could have it how they wanted without affecting the code. He still put up a fight. Only once I showed him that practice in action and how SCC still saw it as exactly the same did the light bulb finally come on.
|
|
|
|
|
My pet hates are underscores, capitalisation and anyone not using TAB set you = 2 spaces (SSMS uses 8 ).
Even if you use tabs and the size of the tabs are different it can totally screw up the formatting when changing developer, irritating to say the least.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: My pet hates are underscores
+5 on that one. I think it makes code so unreadable.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
So how do you easily differentiate between local variables, method parameters and class members?
|
|
|
|
|
A common trick with VMs is to apply lazy-loading to your commands. What you do is
private RelayCommand loadCommand;
public RelayCommand LoadCommand
{
get
{
if (loadCommand == null)
loadCommand = new RelayCommand((o)=> LoadSomeViewExecute, new Predicate<object>(CanLoadExecute));
return loadCommand;
}
}
|
|
|
|
|
Cheers Pete, I have used lazy loading with CSLA and will definitely take a look at this.
I am quickly getting around C# syntax and 'un-learning' some VB hacks!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi Friends
I want the WPF for the VB.Net(WinForm) to make a of Components
The ElementHost do not want to use
Thank you
|
|
|
|
|
If you're going to be hosting WPF inside WinForms, then you need the ElementHost, or you're going to have to write your own, which will end up doing what ElementHost does anyway.
|
|
|
|
|
WPF and Winforms are different programming languages and you should try and use only one or the other.
You can call one type in another, but it should only be for legacy systems and really not for any new application.
|
|
|
|
|
|
I am looking for latest books or tutorials... not the old or outdated ones...Books or tutorials with hands-on or practical examples... Thanks.
|
|
|
|
|
Please check <a href="http://joshsmithonwpf.wordpress.com/advanced-mvvm/">http://joshsmithonwpf.wordpress.com/advanced-mvvm/</a>[<a href="http://joshsmithonwpf.wordpress.com/advanced-mvvm/" target="_blank" title="New Window">^</a>] from the WPF guru.
|
|
|
|
|
|
Try to avoid cross-posting.
This question was already answered in the C# forum.
|
|
|
|
|
Abhinav,
Thanks for your comments.. you are right... I recently joined code project... I was not familiar with the site when i joined... Initially I posted this question in C# discussion section... I did not see or realize the WPF/Silverlight forum... Then I posted the question here i thought this was the right place for this question... thanks for your feed back...I'll make sure I don't cross post question in the future...
|
|
|
|
|
|
Hi,
I'm trying to bind my ICollectionView data to a DataGrid and am not getting any data displayed, even though the data is retrieved from my data source.
I am trying to populate my DataGrid with data received as the result of a Button press, and can only assume that the problem is that my ICollectionView data is received on a separate thread. The data is received correctly, and my list is populated fully, but just not displayed.
My XAML is this
<Window x:Class="UPC_Programmer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UPCP="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:GridLines="clr-namespace:UPC_Programmer" Closing="Window_OnClosing"
xmlns:tree="clr-namespace:Aga.Controls.Tree;assembly=Aga.Controls"
x:Name="DataTree"
<ToolBarPanel Height="26" HorizontalAlignment="Stretch" Margin="1,22,0,4"
Name="toolBarPanel1" VerticalAlignment="Stretch" Width="800" Orientation="Horizontal"
Background="Gray" Grid.ColumnSpan="4">
<Button x:Name="Controller_Read" Height="25" Width="50" Click="OnReadBtnClk"
IsEnabled="False">
</Button>
</ToolBarPanel>
<DockPanel Height="448" Width="801" Grid.ColumnSpan="4"
Margin="0,51,0,29" Grid.RowSpan="2">
<UPCP:DataGrid DataContext="{StaticResource GroupedCustomers}" ItemsSource="{Binding}"
AutoGenerateColumns="False" Grid.Row="1" Height="447" HorizontalAlignment="Left"
Name="dataGrid2" VerticalAlignment="Top" Width="799" Grid.ColumnSpan="4">
<UPCP:DataGrid.Columns>
<UPCP:DataGridTextColumn Header="Parameter" Width="400"
Binding="{Binding Path=TagName}" Foreground="Black"/>
<UPCP:DataGridTextColumn Header="Value" Width="50"
Binding="{Binding Path=Value}" Foreground="Black"/>
<UPCP:DataGridTextColumn Header="" Width="50"
Binding="{Binding Path=Value3}" Foreground="Black"/>
</UPCP:DataGrid.Columns>
</UPCP:DataGrid>
</DockPanel>
</Window>
And my Code Behind is similar to that below
public partial class MyClass
{
public ICollectionView GroupedCustomers { get; private set; }
private MY_LIST<MY_VALUES> currentValueList = null;
private void OnReadBtnClk(object sender, RoutedEventArgs e)
{
RequestService(LIBRARY.LIB.OFFERED_SERVICES.GET_CURRENT_VALUES);
}
void OnValueListReceived(object sender, ValueListConnectionHandlerEventArgs e)
{
if (e.GetValueList.List != null)
{
this.currentValueList = e.GetValueList;
if (this.currentValueList.Count() > 0)
{
LoadData();
}
}
}
private void LoadData()
{
_TagCollection.Clear();
foreach(VALUES item in currentValueList)
{
try
{
if (item.GetValueType == TYPE_INT)
{
MemoryStream ms = item.GetValueStreamed;
BinaryFormatter bFormatter = new BinaryFormatter();
ms.Position = 0;
String strParam = item.GetIndex.ToString();
String strValue = item.GetSubIndex.ToString();
String strValue2 = item.GetPoohId.ToString();
String strValue3 = item.GetNodeId.ToString();
Group eGroup = GetGroupEnumFromID("1");
_TagCollection.Add(new TagData { TagName = strParam, Value = strValue, Value2 = strValue2, Value3 = strValue3, Group = eGroup });
}
}
catch
{
}
}
GroupedCustomers = new ListCollectionView(_TagCollection);
dataGrid2.Items.Refresh();
}
}
}
My list, GroupedCustomers, is populated with the right amount of data, but my dataGrid doesn't display the data.
Any thoughts would be much appreciated.
Regards
Tony
modified 9-Nov-12 3:08am.
|
|
|
|