I am subclassing ListView in a Windows Universal App Project. I create a new UserControl in Visual Studio 2015 RC and then change the UserControl type to ListView in both XAML and codebehind.
When I insert the control and run the application I get a 'Xaml Parsing Failed' exception without any further information.
Upon researching I came across the issue where the project name contains a dot, but my project name does not contain such characters.
Any Idea how to research this further?
EDIT: I also tried subclassing ListView, GridView, ListBox and Itemscontrol. Itemscontrol does not generate the error but all others do.
EDIT 2:
Created a new Universal App Project in VS2015 RC
Add -> UserControl
Changed Base Class into:
public sealed partial class ListViewEx : ListView
{
public ListViewEx()
{
this.InitializeComponent();
}
}
Changed XAML UserControl tag into ListView
The answer from MSDN forums: use themed control (custom control) for this case.
However, this approach works in WPF, it surprises me.
Related
I am developing a C# Windows Form project with Visual Studio 2019. I have inherited a new control, called NewGroupBox, from System.Windows.Forms.GroupBox, the control is under name space MyProject.NewCtrls and was added through the standard procedure How to: Inherit from Existing Windows Forms Controls. I did not do any change on the code generated except changing public partial class NewGroupBox: Control to public partial class NewGroupBox: GroupBox
In the main frame, I have a GroupBox object called groupbox_Table.
groupBox_Table = new System.Windows.Forms.GroupBox();
The form designer could open normal. However, if I manually changed GroupBox with NewGroupBox
groupBox_Table = new MyProject.NewCtrls.NewGroupBox();
The form designer cannot be opened properly. The error message shows "Could not find type 'MyProject.NewCtrls.NewGroupBox' ...". Of course the type is defined in my project and there is no error when building the project.
How do I fix this problem so that form designer can open normally? Thanks a lot!
I'm developing a simple application. I got two projects in the solution
1 WPF Custom Control Library
2 Windows Forms Application
I'm rendering some 3D visualization on WPF and I got that embedded in the windows form as UserControl. So here is what I need to do in this project.
I've got
public void BuildObjectTest(InsertionPoint insertionPoint, Points point) that visualize one object.
Anyway I want it multiple times from my windows Form application because I need to show several objects. I've got a textbox that when I write "barcode" I've got several object items in a LIST that show some label information and buttons PREVIOUS and NEXT. So I have to think in that way is it possible to add code in the constructor runtime or is there any other way I can do that?
This is how the constructor looks like:
public UserControl1()
{
InitializeComponent();
InsertionPoints insertionPoint=new InsertionPoint(0,50,48);
Points points=new Points(100,50,20);
BuildObjectTest(insertionPoint,points);
VisualizeBoxSides();
}
To update UI in WPF Form, I had to use:
userControl.Dispatcher.Invoke(() =>
{
userControl.BuildObjectTest(insertionPoint,points);
});
Cheers all,
I'm searching to use the devexpress tool in my visual c# project (vs2013). I'm also using caliburn.micro and i've inserted the Caliburn.Micro.DevExpress reference. So, this is my environment.
The problem: I want create a container, where you can open some predefined tabs. You can navigate in the open tabs, close them and open others.
I'm in stuck with the integration of devexpress and caliburn. Without caliburn and mostly without MVVM pattern, it's easy. But how can I do this using my viewModel?
The result I want is like the example "Simple MDI" in [the official caliburn.micro documentation1]. Instead of the button "open tab", I've my menu in the upper side and, depending on which button is clicked, I want open the relative dockpanel/tab.
Now, in the xaml file, my container is a devexpress object, the "DocumentGroup". My goal is to add dynamically the DocumentPanel(s), like written above.
Is it clear the problem? Some ideas for solution?
UPDATE: in my viewModel I have:
namespace **.ViewModels
{
class MainWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
public void addT() {
Debug.WriteLine("start");
ActivateItem(new ucImpiantiViewModel());
Debug.WriteLine("end");
}
}
}
And in the xaml I have:
...
<dxd:DocumentGroup x:Name="Items" ItemHeight="3*" SelectedTabIndex="0">
...
I thought this way was good, but still nothing.. the good new is only that the console.writeline are working!
actually i am developing a universal app for Windows and Windows Phone.
Within that app i am using dependency properties to assign data to properties of custom user controls in XAML. The problem is that the compiler says he is not able to find the property were i would like to bind data to.
The button definition looks like the following.
public sealed partial class RulerButton : UserControl
{
public static readonly DependencyProperty BackendProperty =
DependencyProperty.Register("Backend", typeof(GlobalData),
typeof(RulerButton), new PropertyMetadata(null));
public GlobalData Backend
{
get { return (GlobalData)GetValue(BackendProperty); }
set { SetValue(BackendProperty, value); }
}
public RulerButton()
{
this.InitializeComponent();
}
}
I use this button within my main page like this.
<btn:RulerButton Backend="{Binding ElementName=root, Path=BackendSource}"/>
Then the compiler says Unknown Member "Backend" in Element "RulerButton".
If have used the same approach earlier in other projects (Normal WPF-Windows applications) and it worked well. So i think the problem is related to universal app projects.
All other questions i have found could not solve my problem.
I would be appreciated if someone could give me a hint.
greets
Edit
Well i actually have solved the problem. But i think it is very curious. Beside the RulerButton i have many other controls where i added the same dependency properties. On some of them i did not add the normal property Backend yet. Cause i first wanted to make the RulerButton work. After completing these controls so that each of them has a BackendProperty and Backend attribute, all errors were gone.
anyway thanks for your help guys
Well i actually have solved the problem. But i think it is very curious. Beside the RulerButton i have many other controls where i added the same dependency properties. On some of them i did not add the normal property Backend yet. Cause i first wanted to make the RulerButton work. After completing these controls so that each of them has a BackendProperty and Backend attribute, all errors were gone.
Trying to use the solution to this question gives me a weird problem. (Replicated here for convenience)
This is a solution for an issue with ListView swallowing the right-click event and preventing the AppBar from opening - A class which inherits ListView and overrides the OnRightTapped event of ListViewItem:
public class MyListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
return new MyListViewItem();
}
}
public class MyListViewItem : ListViewItem
{
protected override void OnRightTapped(Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{
base.OnRightTapped(e);
e.Handled = false; // Stop 'swallowing' the event
}
}
<CustomControls:MyListView
x:Name="ItemsList"
...
SelectionMode="Single"
RightTapped="MyListView_RightTapped">
</CustomControls:MyListView>
I have implemented a custom control as specified, in a new namespace called CustomControls, exactly as described. I've added that namespace to MainPage.xaml
xmlns:CustomControls="using:CustomControls"
When I then try and reference 'ItemsList' in code behind, I get a compile error
The name 'ItemsList' does not exist in the current context
I've tried building, rebuilding, cleaning the solution, closing and reopening the solution, putting the classes under the main project namespace, all to no avail.
To summarise, MainPage.cs cannot see a Custom Control on MainPage.xaml
UPDATE 2: Reworded the question to remove irrelevant issues. I've also changed the title to reflect the real issue.
I was using Name but should have been using x:Name. Apparently custom controls and user controls need to use x:Name rather than Name to be seen in code behind.
More info on the difference here:
In WPF, what are the differences between the x:Name and Name attributes?