|
With "ViewModel" I mean a class that encapsulates all data for one row. Don't know what might be weird about this. It's just a capsule of data for the columns for each row plus the visibility flag.
|
|
|
|
|
Hi all,
I added to an already working (perhaps that was my mistake) a DataGridTemplateColumn containing a Button. The code looks like this:
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:MyAssembly;assembly=MyAssembly>
<Button x:Name='btnShowSubgrid' Tag='{Binding ID}' Click='btnShowSubgrid_Click' Margin='4' Width='20'>
<Button.Content>
<Image x:Name='imgButtonTemplate' Source='Images/rightBlueArrow.png' />
</Button.Content>
</Button>
</DataTemplate>
All columns are runtime generated, and again, if I don't add this column, it all works fine.
This button's tag is bound to a column called "ID". There is another column that binds to "ID" but I don't think that's an issue. Even went as far as to remove all "embellisher" tags and content only leaving it with x:Name only but no luck.
This is how I add the column:
DataGridTemplateColumn buttonColumn = new DataGridTemplateColumn();
using (StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAssembly.CellTemplates.ButtonCellTemplate.xml")))
{
String str = reader.ReadToEnd();
str = str.Replace("(ColumnToBind)", _gridDefinition.SubGrid.Param);
buttonColumn.CellTemplate = (DataTemplate)XamlReader.Load(str);
}
dgGrid.Columns.Add(buttonColumn);
The ArgumentOutOfRangeException is thrown after the MainPage_Loaded event and it says:
Microsoft JScript runtime error: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
at System.Windows.PresentationFrameworkCollection`1.InsertDependencyObject(Int32 index, DependencyObject value)
at System.Windows.Controls.UIElementCollection.InsertInternal(Int32 index, UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Insert(Int32 index, T value)
at System.Windows.Controls.DataGrid.InsertDisplayedColumnHeader(DataGridColumn dataGridColumn)
at System.Windows.Controls.DataGrid.OnApplyTemplate()
at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
My DataGrid has AutoGenerateColumns set to "false". Has somebody have the same issue? How have you fixed it?
BTW, I'm using Silverlight 4.
All help is appreciated!
Thanks,
humble.apprentice
|
|
|
|
|
Hi
I want to host wpf controls in a legacy windows form. I have to do something like this
[code]
// In some windows form class
void SetWPFContent(UIElement content)
{
ElementHost ctrlHost = new ElementHost();
ctrlHost.Child = content;
ctrlHost.AutoSize = true;
ctrlHost.Dock = DockStyle.Fill;
Controls.Add(ctrlHost);
}
[/code]
The WPF control is put in the form. However, the ElementHost component always come out with the same odd size no matter what content is. Is there a way for me to resize ElementHost to make it fit the content?
thanks
|
|
|
|
|
Hi,
I have a ViewModel called MainWindowViewModel. In this I have a property that shows a modal window when an error occurs. This works fine as long as an error occurs during start-up.
When an error occurs after start-up, in SubViewModel, I invoke the parametrized constructor in MainWindowViewModel.
MainWindowViewModel.cs
public MainWindowViewModel()
{
if (!isServerRunning)
{
this.ModalWindow = new LogViewModel("Service is down.");
}
else
{
this.ModalWindow = new LogViewModel();
}
}
public MainWindowViewModel(string logMessage)
{
this.ModalWindow = new LogViewModel(logMessage);
}
public LogViewModel ModalWindow
{
get
{
return _modalWindow;
}
set
{
_modalWindow = value;
OnPropertyChanged("ModalWindow");
}
}
MainWindow.xaml
....
<Grid>
<vw:LogView Content="{Binding Path=ModalWindow}"/>
</Grid>
- MainWindowViewModel is bound to MainWindow.xaml
- SubViewModel is bound to SubView.xaml
- MainWindow.xaml loads multiple views, one of them is SubView.
In App.xaml I have created an instance of the ViewModel and bound it to MainWindow.
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MainWindow mainWindow = new MainWindow();
MainWindowViewModel viewModel = new MainWindowViewModel();
mainWindow.DataContext = viewModel;
mainWindow.Show();
}
What I realized was that the modal window shows up when an error occurs after start-up if I create the modal window property in SubViewModel and bind it to SubView. But this is not ok since SubView is only a DockPanel covering 1/4 of the MainWindow. I.e. 1/4 is only covered with a modal window instead of the whole MainWindow.
I am not sure why modal window does not appear in MainWindow when I call the parametrized constructor from SubViewModel. When I debug I see that the part "_modalWindow = value;" has correct values but in any case the modal window does not show up.
I am binding the ViewModel to the Datacontext of the MainWindow. That's is probably why I see the Modal window when error occurs on start-up. For errors after start-up: Must I (from SubViewModel where I invoke the parametrized constructor in MainWindowViewModel) do some kind of binding to the datacontext of the Mainwindow again? How is the best way of doing this without having to create a new instance of MainWindow? Because MainWindow should only be created once.
Any help is much appreciated.
modified on Tuesday, June 14, 2011 4:33 AM
|
|
|
|
|
This problem is solved.
I passed the instance MainWindowViewModel to SubViewModel and used that instance in SubViewModel to set the property in MainWindowViewModel.
|
|
|
|
|
I have a project (LKCommon) set up in my app solution to hold common resources - I have added a reference to that assembly to the main assembly and then try to access the resources using:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/LKCommon;component/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Converters -->
<converters:OrientationToAngleConverter x:Key="OrientationToAngleConverter" />
</ResourceDictionary>
</UserControl.Resources>
If I change any of the pack uri string it says it can no longer find the file (so it seems to be finding it during development) but as soon as I run the application I get a file not found exception for that resource dictionary.
What am I doing wrong?
|
|
|
|
|
I think you need to get rid of the application:,,, portion and it should work. Where 'xxx' is the assembly name minus the extension. What you have now is trying to load out of the exe.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/xxx;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
|
|
|
|
|
I tried that but it didn't work at the UserControl level - only at the Application level. So that is what I have gone for. Thanks for your reply.
|
|
|
|
|
Hi
I am getting this error when I am trying to call sharepoint 2010 client object model in my silverlight application.Error:The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
using (SP.ClientContext objSite = new SP.ClientContext("http://Sharepoint:80/"))
{
SP.CamlQuery objCaml = new SP.CamlQuery();
objCaml.ViewXml = @"<View></View>";
SP.Web objWeb = objSite.Web;
SP.List list = objWeb.Lists.GetByTitle("BackgroundImages");
listItems = list.GetItems(objCaml);
objSite.Load(objWeb);
objSite.Load(list);
objSite.Load(listItems);
objSite.ExecuteQueryAsync(Succeeded, Failed);
}
Please help
|
|
|
|
|
Hi all,
I have developed an application using Silverlight 4.0 which uses the Twilight Blue theme thats available on codeplex. I have a datagrid which uses a datapager whose "DisplayMode" is set to "FirstLastPreviousNextNumeric".My requirement is to highlight the currently selected page in the datapager.
I tried myself and was unable to find any style property that corresponds to manipulating the current page style. Googling also didn`t help. Any help would be appreciated.
When you fail to plan, you are planning to fail.
|
|
|
|
|
|
Thanks for your reply, however i had already went through this documentation after googling the problem. The documentation says that we have a part called "CurrentPageTextBox" of the datapager class which can be styled but the fact that i am using the display mode "FirstLastPreviousNextNumeric" doesn't have a textbox!!!! Why doesn't the datapager have a "CurrentPageButton" or a "CurrentPageTextBlock" part !!!!
When you fail to plan, you are planning to fail.
|
|
|
|
|
Good Evening All
I want to create a unique value for my User in Silverlight and access this value on the asp.net page that is part of the silverlight website. So i cant use cookies because they wont work and i cant do the client site cookie thing because it does not work for my design, its complicated.
This is my current implementation, i created a temp table that i store a value on t he SQL and retrieve it on the SQL immediately, because the created or the value and the access of the value happens between 1 nanosecond. so i don't want to depend on that because on a multi user system that will be a problem.
So basically i need to store any unique value that i can retrieve from the database even in a multi user environment.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
What about a GUID (uniqueidentifier in SQL server)?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The main problem here is that the aspx page that i want to interact with is not the one that host the silverlight plugin, so in my project i have my xaml project and when that gets compile you know it will create a xap file that will be used by the hosting aspx page. but ow the page i want to interact with its not the same page that host it, i would have used the InitParam's. So the catch is that if i create a GUID on the SIlverlight and store it in the Db , how will asp.net select the correct GUID in a multiuser environment.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Silverlight code runs on the client and ASP.NET code runs on the server....so do you really need Silverlight to interact with the page HTML on the client? Sounds more like you need sessions and/or a way to communicate between Silverlight and the server code - a simple web service, WCF, or whatever.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i have exhausted the javascript solutions or client side solution, i have never thought of carrying the session in a webservice. can you please elaborate on what you mean some post a link that shows what you are suggesting?
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
If you search on "Silverlight ASP.NET Sessions" you'll find info, for example here's one article:
Access Sessions from Silverlight and ASP.NET[^]
Not sure how you're going to get at the page in the embedded telerik control....you should consult the TElerik documentation for that.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Does ASPX have access to SL protected data storage on the client(I have no idea)?
When you start your SL app pass in a guid from the ASPX shell app and use that in SQL servers temp table. Bloody horrible solution.
I'm passing report criteria from an SL app to a popup via the url, maybe a work around there, maybe a hidden window using the options!
private void DoReport(object sender, RoutedEventArgs e)
{
string sRepName = (sender as Button).Tag.ToString();
string sRepCrit = string.Empty;
switch (sRepName)
{
case "lineset":
sRepCrit = VM.SelectedRoom.RoomID.ToString();
break;
case "equipmentlist":
sRepCrit = GetCriteriaEQ();
break;
}
string sURL = VM.GetReportsAddress( sRepName, sRepCrit);
HtmlPopupWindowOptions options = new HtmlPopupWindowOptions();
options.Left = 0;
options.Top = 0;
options.Width = 810;
options.Height = 600;
if (true == HtmlPage.IsPopupWindowAllowed)
HtmlPage.PopupWindow(new Uri(sURL), "new", options);
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi Mycroft
You see my problem here is that i have an Silverlight Child Window that is hosting a htmlContainer(Telerik) it is like an iframe object , so this html container is hosting an aspx page, and when that childwindow loads , i store the value to the database and immediately, when the htmlcontainer loaded event gets fired, i have a constructor on the aspx page, that immediately gets the values from the db. This happens so fast that the possibility of a conflict in a multi user environment is less, but i don't trust the approach , i want to retrieve the value and know who's value is for.
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I would like to know how to implement the following xaml in code, specifically the input binding to a command.
<Controls:TextBox Text="{Binding Path=SearchText, UpdateSourceTrigger=PropertyChanged}">
<Controls:TextBox.InputBindings>
<KeyBinding Key="Return" Command="{Binding Path=SearchCommand}"/>
</Controls:TextBox.InputBindings>
</Controls:TextBox>
The reason for the question is i am looking to inherit from some of the default windows controls, and have some standard behaviour for my inherited control. I wish for the return and escape keys to execute a commands in my ViewModel which will be the DataContext for the Inherited Control. The return key would trigger a search to be performed, and the escape key would clear the control to its default value, any help would be greatly appreciated.
|
|
|
|
|
Sounds like the perfect use for attached behaviors!
|
|
|
|
|
The following appears to impelemtn what you suggested, to be honest i'm not sure that i understand the need/benifit to use an attached behaviour insted of inheriting from a control.
public static class LookupBehaviour
{
public static Boolean? GetEscapeToClear(ComboBox comboBox)
{
return (Boolean?) comboBox.GetValue(EscapeToClearProperty);
}
public static void SetEscapeToClear(ComboBox comboBox, Boolean? value)
{
comboBox.SetValue(EscapeToClearProperty, value);
}
public static readonly DependencyProperty EscapeToClearProperty = DependencyProperty.Register("EascapeToClear",
typeof (Boolean?),
typeof (LookupBehaviour),
new UIPropertyMetadata(null, OnEscapeToCearChanged));
private static void OnEscapeToCearChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is ComboBox)) return;
var cmb = d as ComboBox;
if ((e.NewValue is Boolean?) && (e.NewValue as Boolean?).HasValue)
{
var escapeBindingCommand = new KeyBinding(ApplicationCommands.NotACommand, new KeyGesture(Key.Escape));
var escapeBidning = new Binding("EscapeCommand");
BindingOperations.SetBinding(escapeBindingCommand, InputBinding.CommandProperty, escapeBidning);
cmb.InputBindings.Add(escapeBindingCommand);
}
}
}
One thing that i didn't like was when creating the key binding that you have to specify a tempory command, ApplicationCommands.NotACommand, and then bind over the top of it, if there is any way to avoid that please let me know. Thanks for the origional reply.
|
|
|
|
|
From your original post, it sounded like you wanted to add the same exact functionality to several different controls. If that was/is the case, then think about it: Its easier to write ONE attached behavior vs a bunch of MyComboBox, a MyButton, a MyCheckBox, etc controls and C&P the code.
The behavior you wrote is hard coded to the ComboBox, but it doesn't have to be hard coded to any specific control type, it can be much more generic. Then you can simply attach it to any control you like. Think of something like a tooltip control. By using attached behaviors, you could attach the tooltip to any control you like.
In addition, attached behaviors allow you to modify a controls' behavior without re-templating an entire parent control just to change an embedded control type. I.e. say you had a data grid and wanted to change the behavior on a ComboBox deep down in the visual tree. You'd have to re-template the entire data grid just to change a <ComboBox /> to a <MyComboBox />.
In regards to your last question, there is no need to create a temporary command and use InputBindings. Just subscribe to the KeyDown message and trap the ESC key.
|
|
|
|
|
In my wpf application, there is a listbox a several textboxes.
On clicking an item in the listbox, the textboxes are populated accordingly.
Do you know why the following happens?
select an item in the listbox.
textboxes are populated with other fields for the selected item. Let's say textbox1 has an empty value.
Type "hello" in the textbox.
select another item from the listbox.
Now in the listbox, select the original item you selected. the textbox has the value "hello".
If application is closed and re-opened then obviously the word "hello" is not there.
Do you see why the value is retained eventhough the data is not saved into the database?
Thanks
|
|
|
|