|
Hi everybody,
I just installed vs2013 and I carried a WPF project, previous developed with VS2010, under this environment. Happens to me a very strange thing that obviously does not happen with 2010 .... I have my own custom control that defines a runtime URI to a dictionary ... the strangeness lies in the fact that in the code of xaml page when i define the use of my control, i've got the error reported in subject... but the strangest thing is that if i start the dubug, everything works fine and the style is correctly applied .... someone has an idea?
the code look like that :
the custom control
using System;
using System.Windows.Controls;
using System.Windows;
using System.ComponentModel;
using System.Windows.Data;
namespace myListView
{
public class myListView : ListView
{
protected override void OnInitialized(EventArgs e)
{
Uri uri = new Uri("Skins\\myDictionary.xaml", UriKind.Relative);
dictionary = Application.LoadComponent(uri) as ResourceDictionary;
base.OnInitialized(e);
}
}
}
the xaml page
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xlw="clr-namespace:myListView;assembly=myListView"
Title="MainWindow" Height="350" Width="525">
<Grid>
<xlw:myListView>
<!-- the editor tell me that can t find the Skins/myDictionary.xaml -->
</xlw:myListView>
</Grid>
</Window>
P.S. The custom control is an external dll included in Reference...it's one of my several generic object that i use in several solution
modified 10-Jan-14 6:04am.
|
|
|
|
|
I find that the xaml design interface regularly fails when dealing with custom controls and particularly complex layouts, this is not new to 2013.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thank you for your reply...but have you ever find a workaround ? i can't believe that i can't migrate my project to the new platform....
|
|
|
|
|
You mean a new version!
I believe is is probably a bug in VS where is the xaml is too complex and it fails to render it. As irritating as it is I have never bothered to try and resolve the issue as it rarely happens and the resolution would probably take too much time anyway.
I now try and keep a views complexity down
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i don't think it's a complexity problem....i add a simple example in my first post where i've got the problem...
|
|
|
|
|
As Mycroft has stated it's a XAML designer issue. The same bug is in VS2012.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Unbelivable ! I'll try to send the bug report to Microsoft tech support...
|
|
|
|
|
I am trying to create a UI where I can move objects around. At the same time I need to be able to interact with the objects.
I am following this example[^].
I have looked at this many times before, and it get confusing, but I do understand some of it.
So far I have this:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\AppResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- MoveThumb Template -->
<ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type classes:MoveThumb}">
<Rectangle Fill="Transparent"/>
</ControlTemplate>
<!-- ResizeDecorator Template -->
<ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
<Grid>
<classes:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
<classes:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0" VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
<classes:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0" VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
<classes:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
<classes:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<classes:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<classes:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
<classes:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</ControlTemplate>
<!-- Designer Item Template-->
<ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<classes:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
<Control Template="{StaticResource ResizeDecoratorTemplate}"/>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
</Window.Resources>
<Canvas Grid.Row="2"
Grid.Column="0"
Background="Transparent">
<ContentControl Name="DesignerItem"
Width="100"
Height="100"
Canvas.Top="100"
Canvas.Left="100"
Template="{StaticResource DesignerItemTemplate}">
<TextBox Grid.Row="1"
IsHitTestVisible="False"
Text="This is some text"
Height="Auto">
</TextBox>
</ContentControl>
</Canvas>
When I run it, I see Resize handles on all 4 corners of the textbox, and I can click & drag. The problem is that I cannot edit the text in the text box because the IsHitTestVisible property on the textbox Is False.
Set IsHitTestVisible = true and you can no longer drag & resize.
What I'd like is to be able to both drag/drop AND edit.
Can anyone help?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
You are trying to implement something like this; WPF Surface Panel[^]
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
wow i am fighting with this for 2 days now !
i am displaying the result of this linq query in a wpf datagrid
var v = from p in _context.EXAMENS_VALEURs
join b in _context.EXAMENS_TYPES_VALEURs on p.EXV_ID_VALEUR_TYPE equals b.ID_EXAMEN_TYPE_VALEUR
join c in _context.EXAMENS_TYPES_GROUPEs on b.EXTV_ID_GROUPE equals c.ID_EXAMEN_TYPE_GROUPE
select new ValeursResult()
{
ID = p.ID_EXAMEN_VALEUR,
Designation = b.EXTV_DESIGNATION,
Groupe = c.EXTG_DESIGNATION,
Valeur = p.EXV_VALEUR
};
((CollectionViewSource)this.FindResource("ExamensView")).Source = v.ToList();
the ValeursResult type is declared like this
public class ValeursResult
{
public int ID { get; set; }
public string Groupe { get; set; }
public string Designation { get; set; }
public string Valeur { get; set; }
}
the datagris id bound to the collectionviewdource with this
<DataGrid x:Name="grd2" AutoGenerateColumns="True"
ItemsSource="{Binding Source={StaticResource ExamensView}}" />
now i can view the result in my datagrid, i can change the values in the cells ,
but the update is not done on the server with
_context.Savechanges()
i have also tried this line of code just before calling savechanges
((ListCollectionView)((CollectionViewSource)this.FindResource("ExamensView")).View).CommitEdit();
but again the databse table is never updated
btw i am using telerik orm with a firebid database
thanks for your help
|
|
|
|
|
I want to learn WPF.
How Can i start learning.
Give me guidance or tutorial about that.
so, i can learn it step by step..
|
|
|
|
|
|
|
I have this HierarchicalDataTemplate. It has a checkbox bound to a property called IsChecked on the DatabaseEntity model:
<HierarchicalDataTemplate DataType="{x:Type entities:DatabaseEntity}"
ItemsSource="{Binding Path=Items}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding IsChecked}"
Grid.Column="0"/>
<Image Grid.Column="1"
Height="16"
Width="16"
Margin="0,0,3,0"
Source="/Osprey.UI.WPF;component/Media/database_64.png" />
<TextBlock Grid.Column="2">
<Hyperlink NavigateUri="{Binding Text}"
Foreground="#0C2DAA"
Style="{StaticResource linkStyle}"
CommandParameter="{Binding}"
Command="{Binding Path=DataContext.SelectedNodeCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={ x:Type views:MainWindowView}}}">
<InlineUIContainer>
<TextBlock Text="{Binding Text}"
FontSize="12"/>
</InlineUIContainer>
</Hyperlink>
</TextBlock>
</Grid>
</HierarchicalDataTemplate>
When I check the checkbox, I'd like the VM to know about it was well as the model. How can I do this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
I assume your model implements INotifyPropertyChanged Interface. In your VM, you can subscribe to the model's property changed event, and then check if the IsChecked property is the one being changed. If the instance of the model is inside a collection (I assume it is as this is a hierarchicaltemplate), you will need to subscribe to the collection's collection changed event, then inside that method, you subscribe to each instance's property changed event.
Something like this
Items.CollectionChanged += ItemsChanged;
private void ItemsCHanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if(e.NewItems != null)
{
foreach(Item item in e.NewItems)
{
item.PropertyChanged += ItemChanged;
}
}
if (e.OldItems != null)
{
foreach (Item item in e.OldItems)
{
item.PropertyChanged -= ItemChanged;
}
}
}
private void ItemChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == "IsChecked")
{
}
}
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Why not raise an event from the model, then subscribe to the event for each item in the list?
If it's not broken, fix it until it is
|
|
|
|
|
The model already has the required event - the propertychanged event
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
modified 13-Jan-14 7:03am.
|
|
|
|
|
Hello,
Please can someone convert me the following xaml code to C# code:
<DataGridTextColumn Header="Ordinal" IsReadOnly="True">
<DataGridTextColumn.Binding>
<MultiBinding
Converter="{StaticResource rowNumberConverter}">
<Binding />
<Binding
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}" />
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
|
|
|
|
|
I think the best thing to do is to convert the xaml headers, like DataGridTextColumn to equivalent classes in C#. The red items in xaml are the properties for that class. For example, the Header and IsReadOnly is most likely in the original DataGridTextColumn class as additional properties. Most xaml headers can be located as similar class names. Finally, the binding could be changed to reference the DataGrid's name instead.
Ben Scharbach
Temporalwars.Com
YouTube:Ben Scharbach
|
|
|
|
|
I am creating a DialogService. I have looked at a bunch and don't like them for various reasons...
Assumptions
a) The serivce will maintain a registry of Views to ViewModels
b) The Views will always be Windows
c) The ViewModels will always inherit from _DialogBaseViewModel.
So here's what I have so far:
Interface
public interface IDialogService<TDialogType, TViewModelType>
where TDialogType : Window
where TViewModelType : _DialogBaseViewModel
{
void RegisterView(TDialogType dialog, TViewModelType viewModel);
bool? ShowDialog(TViewModelType viewModel);
}
Implementation
public class DialogService<TDialogType, TViewModelType> : IDialogService<TDialogType, TViewModelType>
where TDialogType : Window
where TViewModelType : _DialogBaseViewModel
{
private Dictionary<TDialogType, TViewModelType> registry = new Dictionary<TDialogType, TViewModelType>();
public void RegisterView(TDialogType dialogType, TViewModelType viewModelType)
{
bool exists = registry.Where(x => x.Key.GetType() == dialogType.GetType()).Any();
if (!exists)
{
registry.Add(dialogType, viewModelType);
}
}
public bool? ShowDialog(TViewModelType viewModel)
{
TDialogType dialog = registry.Where(x => x.Value == viewModel).Select(x => x.Key).FirstOrDefault();
dialog.DataContext = viewModel;
dialog.ShowDialog();
bool? result = dialog.DialogResult;
return result;
}
}
Usage
public class TestIt
{
public void Test()
{
DialogService<Window, _DialogBaseViewModel> service = new DialogService<Window, _DialogBaseViewModel>();
service.RegisterView(new PersonView(), new PersonViewModel());
service.RegisterView(new InvoiceView(), new InvoiceViewModel());
service.RegisterView(new AnotherView(), new AnotherViewModel());
bool? dialogResult = service.ShowDialog(new InvoiceViewModel());
}
}
Problem
How do I change this so that I register types instead of concrete classes? If you look at the test you can see that I had to create instances to get it to work... This isn't right.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
a rough example.
Interface
public interface IDialogService<TDialogType, TViewModelType>
where TDialogType : Window
where TViewModelType : DialogBaseViewModel
{
void RegisterView(Type dialogType, Type viewModelType);
bool? ShowDialog(TViewModelType viewModel);
}
Implementation
public class DialogService<TDialogType, TViewModelType> : IDialogService<TDialogType, TViewModelType>
where TDialogType : Window
where TViewModelType : DialogBaseViewModel
{
private Dictionary<Type, Type> registry = new Dictionary<Type, Type>();
public void RegisterView(Type dialogType, Type viewModelType)
{
if (!dialogType.IsSubclassOf(typeof(TDialogType)))
{
throw new ArgumentException(string.Format("The dialogType must be a subclass of type {0}.", typeof(TDialogType).Name), "dialogType");
}
if (!viewModelType.IsSubclassOf(typeof(TViewModelType)))
{
throw new ArgumentException(string.Format("The viewModelType must be a subclass of type {0}.", typeof(TViewModelType).Name), "viewModelType");
}
bool exists = registry.Where(x => x.Key == dialogType).Any();
if (!exists)
{
registry.Add(dialogType, viewModelType);
}
}
public bool? ShowDialog(TViewModelType viewModel)
{
Type dialogType = registry.Where(x => x.Value == viewModel.GetType()).Select(x => x.Key).FirstOrDefault();
var dialog = (TDialogType)TypeDescriptor.CreateInstance(null, dialogType, null, null);
dialog.DataContext = viewModel;
dialog.ShowDialog();
bool? result = dialog.DialogResult;
return result;
}
}
Usage
DialogService<Window, DialogBaseViewModel> dialogService = new DialogService<Window, DialogBaseViewModel>();
dialogService.RegisterView(typeof(PersonView), typeof(PersonViewModel));
dialogService.RegisterView(typeof(InvoiceView), typeof(InvoiceViewModel));
dialogService.RegisterView(typeof(AnotherView), typeof(AnotherViewModel));
dialogService.ShowDialog(new PersonViewModel());
|
|
|
|
|
Thank you Sir!
If it's not broken, fix it until it is
|
|
|
|
|
Although answered in the above post, I will say this:
To me, the word "service" screams static class. What use is a service if you have to create it and register all your views every time you are in a different scope? I would create the service class as a static item and register views on it, that way the registered views are available to the entire application without having to recreate the registry.
You would have to use some kind of initialization logic to set up the service (register all the available views) that should be called during the startup process of your program.
|
|
|
|
|
I agree. Just wanted to get it running first. I'll convert it to a static class
If it's not broken, fix it until it is
|
|
|
|
|
So, making it static, I now have:
DialogService<Window, _DialogBaseViewModel>.RegisterView(typeof(SQLConnectionView), typeof(SQLConnectionViewModel));
bool? dialogResult = DialogService<Window, _DialogBaseViewModel>.ShowDialog(new SQLConnectionViewModel());
I'm not sure I like having to specify the types each time I call ShowDialog
If it's not broken, fix it until it is
|
|
|
|