Hi all,
I want to themes apply on different different controls such as button, list box,combo box etc. in WPF.
Thanks.
aniruddha
Hi all,
I want to themes apply on different different controls such as button, list box,combo box etc. in WPF.
Thanks.
aniruddha
I am not sure if this is the right forum to ask this question, but we are seeing an error along the lines in the xaml designer:
The type BooleanToWidthConverter was not found. Check your ....
in the xaml designer regarding a converter and aren't sure why. The code compiles and runs just fine but we can not load the page in the designer nor see the converter in the intellisense.
We do see other converters from the same .cs file in the namespace and they work on the xaml page.
This is the xaml - nothing unusal:
<local:BooleanToWidthConverter x:Uid="anui:BooleanToWidthConverter_1" x:Key="BooleanToWidthConverter"/>
Is there anything wrong with the following converter? What else should I be checking?
[ValueConversion(typeof(bool), typeof(double))]
public class BooleanToWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(bool)value)
{
return 0;
}
else
{
return double.NaN;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Elizzabeth Zelasky
Hi,
Model- Person
ViewModel-MainWindowVW
View-MainWindow
Please help how to acces the textbox.getbindingexpression in viewmodel. Please refer sample code.
i have used updatesourcetrigger=Explcit. After click the save button how to get the New Value in CurrentPerson.
Note: Please don't change updatesourcetrigger=Explcit
public class Person : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { name=value; PropChanged("Name"); } } private int age; public int Age { get { return age; } set { age = value; PropChanged("Age"); } } public event PropertyChangedEventHandler PropertyChanged; public void PropChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public class RelayCommand : ICommand { Action<object> action; Predicate<object> predicate; public RelayCommand() { } public RelayCommand(Action<object> action,Predicate<object> predicate) { this.action = action; this.predicate = predicate; } public bool CanExecute(object parameter) { return predicate(parameter); } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) { action(parameter); } } public class MainWindowVW { Person p; RelayCommand saveCommand ; RelayCommand cancelCommand; public MainWindowVW() { p = new Person() { Name = "Amru", Age = 24 }; saveCommand = new RelayCommand(SaveMethod, ValidateSave); cancelCommand = new RelayCommand(CloseMethod, ValidateClose); } public Person CurrentPerson { get { return p; } } public RelayCommand SaveCommand { get { return saveCommand; } } public RelayCommand CloseCommand { get { return cancelCommand; } } private bool ValidateSave(object p) { return true; } private bool ValidateClose(object p) { return true; } private void SaveMethod(object p) { this.CurrentPerson.PropChanged("Name"); this.CurrentPerson.PropChanged("Age"); MessageBox.Show("[After] Name: " + this.CurrentPerson.Name + " Age: " + this.CurrentPerson.Age.ToString()); } private void CloseMethod(object p) { Application.Current.MainWindow.Close(); } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = new MainWindowVW(); } }<Window x:Class="Command_Explicit.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="125" Width="230" WindowStartupLocation="CenterScreen"><Grid FocusManager.FocusedElement="{Binding ElementName=txtName}"><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="40"/><ColumnDefinition Width="168"/></Grid.ColumnDefinitions><TextBlock Text="Name:" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="3" Grid.Row="0"/><TextBlock Text="Age:" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="3" Grid.Row="1"/><TextBox Name="txtName" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3" Grid.Row="0" Grid.Column="1" Width="160" TabIndex="0" Text="{Binding Path=CurrentPerson.Name,UpdateSourceTrigger=Explicit}"/><TextBox Name="txtAge" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3" Grid.Row="1" Grid.Column="1" Width="160" TabIndex="1" Text="{Binding Path=CurrentPerson.Age,UpdateSourceTrigger=Explicit}"/><StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right"><Button Name="btnSave" VerticalAlignment="Center" Width="60" Height="25" Margin="3" Content="Save" IsDefault="True" Command="{Binding SaveCommand}"/><Button Name="btnCancel" VerticalAlignment="Center" Width="60" Height="25" Margin="3" Content="Cancel" IsCancel="True" Command="{Binding CloseCommand}" /></StackPanel></Grid></Window>
Ahmed
Hi,
I will try to be as clear as possible :-
1. I have a Usercontrol with a TextBox (It has its own View Model) - I
2. I have another UserControl which references the above one (It also has its own View Model)- II
Roughly, this is what the XAML looks for UserControl2 (which references UserControl1) -Please ignore the specifics.
<UserControl x:Class="MyClass" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Controls:UserControl1 DockPanel.Dock="Bottom"
DescriptionUserControl1="{Binding Description, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" /></UserControl>
The Description propertyis exposed via UserControl2's ViewModel which in turn Binds to
the "DependencyProperty" of UserControl1.
Question: When the user types on the TextBox, I want theDescription property of UserControl2's View Model to get updated. I have tried making the Description property as a dependency property but no luck. Whenever I type, it always updates its own Dependency Property
i.e. of the UserControl 1 itself - which I don't care. But during binding (on load) it binds perfectly. But, other way is not working. Basically, the changes of textbox should reflect back to UserControl2, ViewModel.
Hope I am clear.
We've got a solution with 2 projects in it, in C#. Using VS 2012. In the secondary project we've got a Generic.xaml file which has some templates defined in it, for transitions, etc. In order to reference it we have put it into a resource dictionary in the primary project. Here's the App.xaml code:
<Application x:Class="BasicNavShell.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:BasicNavShell" StartupUri="NavShell.xaml"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/NavShellControls;component/Themes/Generic.xaml" /></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources></Application>
We've noticed there's a little squilley (tilda) underneath the opening bracket of the Application tag. Passing the mouse over that reviews the following:
"The property 'Resources' can only be set once."
Well, from our point of view, it looks like it is being set only once. We don't understand what's going on, nor why.
Rod
I have a combo obx that is throwing a exception.
The error in the build says: Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception"
<ComboBox Name="plotCombo" HorizontalAlignment="Left" VerticalAlignment="Center" Height="25" SelectedValue="{Binding Path=SelectedOption, Mode=TwoWay}"></ComboBox>
chuckdawit
I am creating a text changed event for a textbox in Mainwindow and text changed event i call a class after calling that class i want to reset textbox content to "" how to do it easily i used
internalstatic fooNameSpace.MainWindow tW1;// in foo.csMainWindow.tW1.txtBlock1.Text="This is a paragraph";
but it doent work
i tried in foo.cs
MainWindow mw = new MainWindow(); mw.textbox.text="";
still nothing i want to change textbox.text="" in my current main window which is visible and if i put it inside textchanged event handler then it is cleared so fast that i am not even able to see it
any help would be highly appreciated?
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
Hi,
I have noticed that when I press the numpad minus (-) the TreeView will collapse the current tree branch. I want to disable this temporarily sometimes as it steals focus from the TreeViewItem that was selected before the minus was pressed. But I don't want to prevent the KeyUp event from reaching down to my controls inside the TreeViewItems, because I need that minus (and any other keys pressed) to reach the KeyUp event in those controls.
So is there a way to temporarily tell the TreeView to ignore all key events but still let them propagate to all its children controls? By "ignore" I mean "don't steal my focus!"
Thanks!
Stoffi Music Player
A simple approach to music
www.stoffiplayer.com -
blog.stoffiplayer.com - dev.stoffiplayer.com
A free and open music application developed in C# using Windows Presentation Foundation.
I'm hoping someone can help me with the below problem. I have a dynamically generated list of radio buttoms in a user coltrol. when I select a radio button a string containing a name of the radio button is passed as a parameter to Execute metod below and an error is generated.
[DebuggerStepThrough] public Boolean CanExecute(Object parameter) { return _canExecute == null ? true : _canExecute((T)parameter); } public void Execute(Object parameter) { _execute((T)parameter); }
<DataTemplate DataType="{x:Type sys:String}" x:Key="RadioButtons"><RadioButton Margin="0,3" Content="{Binding .}" GroupName="radios" Command="{Binding ElementName=ItemOptionList, Path=DataContext.ViewInstrumentOptionCommand}" CommandParameter="{Binding}" /></DataTemplate>
wesley
Is it possible to dynamically allocate WPF controls? For example, I want to have a ScrollViewer, with a TextBox inside, and allocate an additional TextBox every time the last one becomes filled. I want to associate this with a Linked List data structure, so that there is no predetermined limit on the number of values.
Hey guys,
I have created a program that creates 3d charts. It creates bars of different length and has hash marks that go up the side for comparison. The whole thing can be rotated, zoom in or out and change the camera angle. What I need now is the legend that will set the value of each mark ($0, $10K, $20K, $30K...). What I think I need to do is to create list in text form and then save that to some type of image format and use that as a texture for another mesh that I'll put beside the chart. So I guess I'm looking for two things. 1.) Is this how you would accomplish this goal...and 2.) How can I create a vertical list of text that I can then save as an image file. I'd really prefer to keep the image file virtual as I don't really need the image for anything other than the chart but if I need to save it to my hard drive I can. I feel as though there should be something out there on this but I can't find it. If you know of a good resource that would also be helpful. I need this in VB.net please!
Thanks
Hey guys,
I know that this is a general question but it is driving me crazy! I'm working on an application that includes WPF forms and what I want to do is to be able to click on a control (in this case RichTextBoxes and Images) and use the mouse to move and resize the control. What I would like to be able to do is to have a generic 'Friends WithEvents Focus_Control as Control' and then assign the Image or the RTB that is clicked to Focus_Control and work with Focus_Control for the other commands. The problem that I'm running into is that when I try to assign an Image to the Focus_Control I get a message that an Image cannot be converted to a System.Windows.Controls.Control. Why is that? They are both System.Windows.Controls. They both have all the commands that I need as all I want to do is move the Margin to change location or Height/Width to change the size. Can someone tell me why this doesn't work and if there is a way to accomplish what I'm trying to do. If they can't work off the same variable then I can just write the duplicate code to handle the two control types but I'd like to understand the difference. Thanks in advance guys!
BTW I'm only asking about the Image as control issue. I've already got everything I need on the movement and resizing issue.
Hello guys,
I am trying to write a custom control and my problem is that the column does not not receive DataContext and therefore cannot do the binding.
My custom control looks like this:
class customControl:ItemsControl { public ColumnCollection Columns { get; set; } .. ... ..... }
Code behind looks like this:
this.DataContext = new ViewModel()
class ViewModel { public list emplyee { get; set;} public string colName1 {get {return "hallo";}}
}
Column looks like this:
class Column : DependencyObject { public static DependencyPoperty Name = DependencyProperty.Register(.........); public string Name { get { ..GetValue(...) } set { ..SetValue(...) } } }
And my XAML looks like this:
<customControl ItemsSource={Binding employees}><customcontrol.Columns><columnCollection><column name={Binding colName1}/></columnCollection></costumControl.Columns></customControl>
Now the problem is that the column does not receive DataContext and cannot bind to the colName1 property which is in DataContext.
How do i solve this? How to pass down the DataContext to objects inside other objects inside other objects?
I am writing a unit test to test a method in a WPF application. The WPF method code is as follow (this is a callback method from the EventAggregator):
private void OnEquipmentListUpdated(object eventArg) { Task.Factory.StartNew( arg => { // Process data from eventArg return an array }, receivedEquipmentListDateTime).ContinueWith( resultData => { // Update CollectionViewSource to update UI }, TaskScheduler.FromCurrentSynchronizationContext()); }
The code works perfectly fine in WPF. When I wrote the unit test to test the method, I create a DispatcherSynchronizationContext with the code below:
var context = new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher); SynchronizationContext.SetSynchronizationContext(context);
However, when I call the method, the ContinueWith part of the codes are not executed. It will only be executed if I create a SynchronizationContext with the code below:
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
How can I test the WPF method in this case? Many thanks in advance for any help.
Hi,
I have a simple WPF app where string messages need to be sent to HTML 5/(javascript) app.
Which is the best way to transfer data.
Also please point to any resources if available.
Hello
I have an entity called Employee with an ObservableCollection<Address> and Address has several properties eg. Town.
Now I'd like to bind directly to the Town value as in
<TextBox Text="{Binding Path=Employee.Addresses[0].Town" />
If Addresses is empty, I get as expected
System.Windows.Data Error: 17 ... ArgumentOutOfRangeException
The application continues running without problems, but an exception is an exception.
I know, I could define in my ViewModel a new string property TownValue, verify if Addresses[0] exists and then assign that value to TownValue and set the Binding to that property.
But I'd prefer some solution on the xaml/Binding side.
Any hints?
Hi,
I'm learning to code in WPF and I was wondering if I could host a windows form within my WPF window (using vb language).
I just want to be able to put some of the windows forms in some tabs instead of having windows popping around everywhere.
Thanks in advance.
PS
I've tried the WindowsFormsHost but that only seems to host the individual objects, I was hoping it would host an entire form itself much like the way the ElementHost in the windows forms can host WPF User Controls.