473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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:WpfApplication1"

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:UserControl1 Margin="20,0,-605,-236.5"
Height="188" VerticalAlignment="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 3133
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...@nnowslpianmk.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 programmatically.

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.Reflection 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
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...
6
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...
3
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...
1
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. ...
1
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...
13
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...
7
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: ...
2
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.