Styling an extended TextBox control in Windows Phone 7 - windows-phone-7

Totally new to custom control creation in Silverlight.
I'm wanting a custom control that inherits from a TextBox control. I've found plenty of tutorials but they all do something like watermarked text or other attached properties. My goal is only to manipulate text at time of entry using the KeyUp event, so visually my TextBox is no different from a standard TextBox.
I created a class file and inherited from TextBox, but at run-time the textbox doesn't display. From what I can gather I need a themes/generic.xaml file, but all of samples I've seen include styles for the additional properties, and in my ignorance I don't know what to change and/or remove.
I'm hoping someone can point me to a generic plain-jane TextBox style definition or a tutorial of such.

What you described should work, I just tried the following and the TextBoxEx renders just fine:
public class TextBoxEx : TextBox
{
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
}
}
You do not need to add a generic.xaml file. This file is used to provide a template which defines the look of your control. You specify the default look of your control by setting the following property:
DefaultStyleKey = typeof(MyControl);
However, as the above TextBoxEx does not set this property, it uses the value inherited from TextBox and hence it inherits the same template (i.e look).

Related

Input mask on an Ajax combobox

I'm using ASP.Net 4.0 to create a web project, and I have two Ajax ComboBoxes on one of my pages. The users have requested input masks on the two ComboBoxes. I can't use the Ajax MaskedEditExtender, since it won't work with a ComboBox. Has anyone ever implemented input masks on an Ajax ComboBox?
DevExpress editors allow you to use masks during editing. Masks are useful when a string entered by an end-user should match a specific format. For instance, you may require a text editor to only accept date/time values in a 24-hour format, only accept numeric values, or only accept numbers that are automatically inserted into the placeholders of a telephone number.
Masked input is supported by the following editor types:
Text box editors (ASPxTextBox and ASPxButtonEdit).
Text box mask settings can be accessed via the MaskSettings property. The editor’s mask can be specified via the MaskSettings.Mask property.
Date editors (ASPxDateEdit).
To enable masked input within a date editor, the UseMaskBehavior property should be set to true. The mask can be defined via the EditFormatString property if the EditFormat property is set to 'Custom'.
In this demo, see how masked input behavior is implemented by entering data into the various types of editors.
learn more here
using System;
using System.Web.UI;
public partial class Features_MaskedInput : Page {
protected void Page_Load(object sender, EventArgs e) {
txtZip.MaskSettings.PromptChar = cmbPromtChar.SelectedItem.Value.ToString()[0];
dateEdit.EditFormatString = cmbDateType.SelectedItem.Value.ToString();
dateEdit.Value = DateTime.Now;
}
}

How to alter a DataTemplate based on a property on the page ViewModel in Windows Phone 7?

I have a ViewModel which contains a Boolean property which tells you if the user has authenticated or not.
I have a WrapPanel which is bound to a collection of profiles. The DataTemplate for these profiles has an icon - a closed padlock for when the user is not authenticated and an open one for when the user is authenticated. Ideally these would be bound to the Boolean on the ViewModel but the DataContext for the templates is the individual profile objects.
I have tried,
Setting the Source selector in the binding as specified here although it appear Windows Phone 7 does not support x:Reference
I tried also the Inversion of Control(?) method detailed here (but containerLocator was not found on my object)
I tried applying a Style.Trigger but these are not supported in Windows Phone 7
I also tried accessing the XAML elements in the code behind and updating programmatically on event triggers, however I could not get a handle on the Image element inside the DataTemplate
Edit after comment: WP7 does not support style triggers. But if anyone is looking for this answer on following versions I let the reply below:
I would use a Style Trigger as seen here to update the icon Source property on the fly - as part of the style of your DataTemplate so you would get a hold of your Image.
One way I found that works based on an answer by Damian Antonowicz but does not implement the full inversion of control method that he uses, is as follows,
Create a partial class which resolves to your view-model instance under your view-model namespace, e.g.
public partial class ViewModelInstanceLocator
{
public AppViewModel AppViewModel // Or whatever the type of your view-model is ...
{
get
{
return App.VM; // Or wherever your view model instance is ...
}
}
}
Define the other half of the class in your XAML page as a resource so that it can be referred to as a static resource, I did this in my App.xaml so that it could be referred to everywhere,
<ResourceDictionary>
<viewmodel:ViewModelInstanceLocator x:Key="ViewModelInstanceLocator" />
...
</ResourceDictionary>
You may need to include the relevant namespace if there is not already a reference to your view-model namespace e.g. at the top,
xmlns:viewmodel="clr-namespace:MyAppNamespace.ViewModel"
Finally to bind to the view-model as follows,
{Binding AppViewModel.SomeProperty, Source={StaticResource ViewModelInstanceLocator}}
The binding updates as usual just as if the view-model instance had been referred to through the DataContext. However, it does not work with design-time data.

Eclipse RCP: How can I update a view when the selected editor changes?

This should be quite a common problem, but I couldn't find anything helpful on the topic.
We are developing an application with Eclipse RCP. The application shows data in an editor of which usually multiple instances are open. In an additional view you can edit the editor-values. When the values are changed in the view they are updated in the editor and it's dirty flag is set.
So far it works fine. What we're missing is: When another editor instance gets the focus, our view should show the data of this editor.
I managed to do that for two views. The second view is sucessfully updated using a TableViewer as selection Provider and registering a SelectionListener in the other view. I tried the same thing for the editor using a Viewer I subclassed from ContentViewer, but it didn't work.
Can this approach be working?
Or do I need a different approach on the problem?
May be you can subclass your view from PageBookView and then provide special adapter for your editor. Outline View is implemented using this approach.
Thank you cerealk, that was exactly what I needed. :-)
Update the View when another Editor is selected
public class myView {
// Create an IPartListener2
IPartListener2 pl = new IPartListener2() {
// If the Editor I'm interested in was updated ...
public void partActivated(IWorkbenchPartReference ref) {
IWorkbenchPart part = ref.getPart(true);
if (part instanceof DetailEditor) {
// ... update the view
Contact contactFromSelectedEditor = ((DetailEditor) part).detailComposite.contact;
detailComposite.update(contactFromSelectedEditor);
}
}
...
}
// Add the IPartListener2 to the page
IWorkbenchPage page = this.getSite().getPage();
page.addPartListener(pl);
}
Why use an IPartListener2 instead of an IPartListener
The IPartListener2 replaces IPartListener with 3.5.
As explained in this this answer:
You should always use IPartListener2 as it can handle part-change events on parts that have not yet been
created because they are hidden in a stack behind another part.
This
listener will also tell you when a part is made visible or hidden or
when an editor's input is changed.

BIRT how to insert text dynamically

I have a report that will require chunks of text (that will be created dynamically) to be embedded from a Java program that runs the report.
Is there a way I can put a text object into the design and then somehow get hold that of that object in my Java program. If this is possible I assume I would be able to insert text into that text object.
Is this the best way to do this?
A code snippet would be gratefully accepted.
Thanks in advance.
You can easily do this by using Java Event Handlers. Any event in the generation process can be modified either by JavaScript (stored on the report design itself) or via a POJO when more complex processing is needed.
Add a TextItem to your report. This will be the intended destination for your block of text. You can add other types of controls and interact with them the same way, TextItem just seems to make sense for this particular question. Add anything you want to the text item, we are going to over-ride the value from the POJO anyway.
Now create a POJO that implements the TextItemEventAdapter interface (this should be in your BIRT distribution). You can then choose what event to bind your POJO to. onCreate probably makes the most sense. To do that, implement the onCreate method from the interface.
/* (non-Javadoc)
* #see org.eclipse.birt.report.engine.api.script.eventadapter.TextItemEventAdapter#onCreate(org.eclipse.birt.report.engine.api.script.instance.ITextItemInstance, org.eclipse.birt.report.engine.api.script.IReportContext)
*/
#Override
public void onCreate(ITextItemInstance text, IReportContext reportContext) {
super.onCreate(text, reportContext);
text.setText(getText());
}
In the above snippet, the getText() method is another method on your class that builds your text block. Implement your business logic here.
Once you have built the class, you need to bind it to the report's text item control. On the report, select the text item. Under "Properties" look for "Event Handler". Here you can add your POJO as the event handler for the control. When the control is rendered, your POJO will now supply the text.
To ease development, have your Java Project and your BIRT project in the same workspace. This will allow the report and the POJO to see each other enabling testing and debugging inside Eclipse.
Here is a lot more background about report events and event handling: http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php
Good Luck!

Allowing user selected Global Theme for winform app

I am using DevExpress controls in a winform app I am building for internal use. My app has about 30 forms in total and I am trying to figure out a way to allow my user's to select a theme. I have seen this mentioned here at SO multiple times in answers to other posts.
I understand how the StyleController works, I believe, but what I am wondering is how I can use 1 Style controller for the whole app.
Right now I am trying to create 1 StlyeController at the Shell form and then pass a reference to it to each child form. From there I then have to programatically set the StyleController property for each control. I don't mind I just wonder, especially from those who have done this, if there is a simpler way?
It is very simple. This example is assuming that you are using skins.
In the constructor of your main form calls:
DevExpress.Skins.SkinManager.EnableFormSkins();
This will enable your form to use the current skin. It is also important that each of your forms derived from XtraForm.
After that you need to setup the global look and feel object for your application:
//This set the style to use skin technology
DevExpress.LookAndFeel.UserLookAndFeel.Default.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
//Here we specify the skin to use by its name
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Black");
If you want to set the look and feel of your application like Office 2003, the setup is different. You just have to call the following function:
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetOffice2003Style();
So, every control of devexpress will use these settings to paint themselves. It is possible to specify a custom LookAndFeel object for some controls but I never used it because I dont see the point to have a custom display for a control or a form.
Exception:
There is one exception in Devexpress framework. The NavBarControl does not use the skin technology automatically from your global LookAndFeel object, you need to specify a setting to enable that:
//To use the current skin
youNavBarControl.PaintStyleName = "SkinNavigationPane";
//To use the current look and feel without the skin
youNavBarControl.PaintStyleName = "NavigationPane";
With version 11.2 I used the information in this article:
http://www.devexpress.com/Support/Center/p/K18013.aspx
In summary :
* Inherit all your forms from XtraForm
* Leave look and feel settings default so that they use the default skin
* Modify the default skin with the following line of code:
DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = "DevExpress Dark Style";

Resources