473,807 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User control refactoring (WPF)

XJ
Hi Expert,
i'm doing some program for my project which using WPF, to create
my application more managible i would apply "user control" concept for
my project for each section of my workspace.

to make my workspace more flexible, all the "namespace" and "user
control" name will store into DB, once user launch my application,
base on different user setting i'm able to load for different user
control accordingly base on on the DB record.

i have 2 question now:

1. How to declare those user control "name space" thru codebehind ?
right now i only able to code my "name space" at XAML
example: xmlns:uccustom= "clr-namespace:WpfAp plication1"

2. How to declare the "user control" name thru codebehind?
right now i also have to declare the user control name at XAML
example: <uccustom:UserC ontrol1 Margin="20,0,-605,-236.5"
Height="188" VerticalAlignme nt="Bottom"/>

* so far i only know to do the setting from XAML, but which is not
enough flexible due to setting concept.please advise , thanks
best regards
Jul 22 '08 #1
3 3154
On Tue, 22 Jul 2008 14:12:07 -0700, XJ <ia*****@gmail. comwrote:
[...]
* so far i only know to do the setting from XAML, but which is not
enough flexible due to setting concept.please advise , thanks
If you can't automatically generate the XAML to layout your UI
conditionally as you like, you can just write C# code to do it. I presume
that's why you're posting here in the C# newsgroup.

Beyond that though, it's not clear what you're asking. You can design
your own UserControl sub-class, and then in the code that goes with your
XAML, just check the database record you care about and conditionally
add/place whatever UserControl instances are appropriate to that database
record (after instantiating them explicitly, of course).

I don't know that there's really any specific answer to your #2 question;
it seems to me that you'd just use XAML to define each UserControl
sub-class as appropriate, as you're already doing. For the #1 question, I
don't understand why the default name space isn't appropriate, nor why you
care, given the rest of what you wrote. But assuming it's important, it
seems like you could just explicitly write a new namespace as appropriate
for your needs (you have to change it in both the .xaml and the .cs file).

Pete
Jul 22 '08 #2
XJ
On Jul 23, 5:54*am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Tue, 22 Jul 2008 14:12:07 -0700, XJ <iany...@gmail. comwrote:
[...]
* so far i only know to do the setting from XAML, but which is not
enough flexible due to setting concept.please advise , thanks

If you can't automatically generate the XAML to layout your UI *
conditionally as you like, you can just write C# code to do it. *I presume *
that's why you're posting here in the C# newsgroup.

Beyond that though, it's not clear what you're asking. *You can design *
your own UserControl sub-class, and then in the code that goes with your *
XAML, just check the database record you care about and conditionally *
add/place whatever UserControl instances are appropriate to that database*
record (after instantiating them explicitly, of course).

I don't know that there's really any specific answer to your #2 question;*
it seems to me that you'd just use XAML to define each UserControl *
sub-class as appropriate, as you're already doing. *For the #1 question, I *
don't understand why the default name space isn't appropriate, nor why you *
care, given the rest of what you wrote. *But assuming it's important, it *
seems like you could just explicitly write a new namespace as appropriate*
for your needs (you have to change it in both the .xaml and the .cs file)..

Pete
Hi Pete,
thanks for your reply, yes, i use C# to develop my
application.
try to imagine, i develop a dockPanel inside my WPF windows ,
which is open for my colleage to post their own "user control" , for
sure my colleage have to develop their own XAML file ( and code
behind) and make as dll , once they done for their User control, they
will goto database to provide the user control name space and user
control name, base on the login , my dock Panel windows will trigger
"their" own user control from my dock panel.

i have no experience to write the code behind to execute and
build the "user control" at runtime.

best regards
Jul 23 '08 #3
On Tue, 22 Jul 2008 17:58:17 -0700, XJ <ia*****@gmail. comwrote:
[...]
try to imagine, i develop a dockPanel inside my WPF windows ,
which is open for my colleage to post their own "user control" , for
sure my colleage have to develop their own XAML file ( and code
behind) and make as dll , once they done for their User control, they
will goto database to provide the user control name space and user
control name, base on the login , my dock Panel windows will trigger
"their" own user control from my dock panel.

i have no experience to write the code behind to execute and
build the "user control" at runtime.
You mention "code-behind", so I'm assuming you're doing some sort of web
application. Hopefully my comments aren't too far off track; they're
based on my experiences with regular non-web applications, but hopefully
the same principles apply.

You really have two parts to your goal: 1) dynamically adding UserControl
sub-classes to your existing WPF window, and 2) providing "plug-in"
support for said sub-classes.

The #1 part is easy enough. You simply instantiate your UserControl
sub-class and add it programmaticall y.

The #2 is more complicated. Creating the DLL with the UserControl
sub-class isn't difficult, but then you need to use reflection to load the
DLL (assembly), and you need to write some code to map the names found in
the database to those found in whatever DLL's have been loaded, and of
course after all that, you need to use reflection to do the instantiation
of the UserControl sub-class as required for part #1. See the
System.Reflecti on namespace for more details.

Whether any of this addresses the two specific questions you asked, I'm
not sure. But it seems like it's the information you actually need given
the stated goal. :)

Pete
Jul 23 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4231
by: =?Utf-8?B?ZGF2ZTMuNQ==?= | last post by:
Are there any plans for a native WPF .Net Framework 3.5 ReportViewer Control? The WinForms ReportViewer Control can be used in a WPF application but it will not compile to a WPF Browser application. We would like to develop a WPF Browser application that can use SQL Server Reporting Services reports. Thanks.
6
7495
by: Vivien Parlat | last post by:
Hello, I hope i'm posting into the good group, i found no active group around xaml. My situation is the following: I'm trying to play around xaml in the new VC# Express 2008. My "aim" (i imagine that when i'll succeed this aim, my understanding will be much better than now) is to create a personalized textbox,
3
4036
by: Eps | last post by:
Hi, I am writing an mp3 player using wpf, I have three user controls (media library, media controls and a playlist). Obviously I need these to interact with each other, I assume the best way to do this is to use events right ?. Can I raise an event on one user control and have one of the others suscribe to it ? or do I need to have the main window suscribe to it and then pass the message on to the target user control ?.
1
2572
by: Linda Liu[MSFT] | last post by:
Hi Moondaddy, I downloaded your sample project and run it on my machine. I did see the problem on my side. The image drawn in the Button is not as clear as that one drawn in the Image control. After doing some research, I found that this is a WPF layout problem. When we place a control into a parent control, if the child control's Width and Height properties are not set, the child control will be streched to
1
1581
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello All-- Just a general (or perhaps loaded) question - is it considered good or bad practice to use code-behind with a CustomControl.generic.xaml file? For instance, with a control I'm creating, it would be nice to use a DispatchTimer to "ramp up" a value, depending on how long the mouse is held down. Thanks,
13
5369
by: =?Utf-8?B?dmlubw==?= | last post by:
Hello, I have created my proper control and i would to rotate it. In the paint event of my object, i have written : Dim graph As Graphics = myObject.CreateGraphics myMatrix = New System.Drawing.Drawing2D.Matrix myMatrix.Rotate(45, System.Drawing.Drawing2D.MatrixOrder.Append) graph.Transform = myMatrix but it don't work.
7
10920
by: Linda Liu[MSFT] | last post by:
Hi George, I have downloaded your sample solution and built it on my machine. I got a compilation error indicating that the type of "CustomResources" doesn't exist in the following xaml code: <Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type res:CustomResources}, ResourceId=CustomExpanderStyle1}}" >
2
5224
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have an existing (WPF) Class Library project that I'd like to add a WPF Custom Control to. However, when I try to Add New Item, that isn't one of the available options. Perhaps this is a brain freeze, but what could I possibly be missing? WtS
2
3053
by: Dean Slindee | last post by:
Is there any control in WPF which can host a WPF window? If not now, are there any plans to improve WPF to implement window hosting. Related question: is it not possible to build a MDI application in WPF. If there is a WPF newsgroup, please direct me there. Thanks, Dean S
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10628
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9195
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5547
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.