Customizing Web Parts - hiding prop in edit mode? - visual-studio-2010

Update:
private string _catalogIconImageUrl = "http://hostname/images/favicon.ico";
[WebBrowsableAttribute(false),
Category("HIDDEN"),
Personalizable(PersonalizationScope.User),
WebDisplayName("Catalog Icon Image url"),
WebDescription("Something")]
public string CatalogIconImageUrl
{
get
{
return _catalogIconImageUrl;
}
set
{
_catalogIconImageUrl = value;
}
}
with the above code, it does not show the image and also when i click on edit the webpart i still able to see the catalogIconImageUrl prop in edit mode
Update end
I've declared the property CatalogIconImageURL in the .Webpart file as follows:-
</property>
<property name="CatalogIconImageUrl" type="string">images/company/companylogo.jpg</property> //sample path...
</properties>
if I click on the Advanced Web Part Gallery as shown below in the screen shot, i able to see that property in editable so my question is, is there a way i can hide this property when user edit the web part? "Catalog Icon Image URL"

You can set the WebBrowseable or Browseable attribute to false
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webbrowsableattribute.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.browsable.aspx
Update:
It is also marked as virtual. This property is a OOTB property in WEb Part class. See here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpart.catalogiconimageurl.aspx
You should override this property and then set the above attribute to false
/// <summary>
/// Catalog Icon
/// </summary>
[Category("Properties")]
[DefaultValue("")]
[Personalizable(PersonalizationScope.Shared)]
[WebDisplayName("Catalog icon image URL:")]
[WebDescription("Enter the WebPart title.")]
[XmlElement(ElementName = "CatalogIconImageUrl")]
[WebBrowsable(false)]
public override string CatalogIconImageUrl
{
}

Related

VisualStudio customize paste operation for my component at design-time

I created WinForm component and I want to replace some properties of my component when developer copy and then paste(not when copy but when paste) component from clipboard at design time.
VisualStudio creates new copy of component and assign properties so it became copy of the source component.
I need to replace some properties on paste operation depending on the selected component.
It is very similar to standard Copy/Paste operation with Control component. When designer change Parent of component if developer select other container (like Panel) before Paste Control.
I think that code to perform it should be somewhere in my ComponentDesigner class.
I explored ComponentDesigner methods but can't find any methods that controls clipboard operations.
You can override the OnParentChanged method of your component, which is executed when the component is pasted onto the form. Then test the DesignMode property to make sure you are in design mode:
public class MyComponent : Label
{
protected override void OnParentChanged(EventArgs e)
{
if (DesignMode) {
// Change properties as desired.
Text = "Design";
}
base.OnParentChanged(e);
}
}
When the component is dropped from the Toolbox, this code is not executed. (I can't explain why, but it happens to be exactly what we need.)
If you derived your component from System.ComponentModel.Component, you can override the property Site; however, this will require some more logic to check whether the component has been pasted.
public override ISite Site
{
get {
return base.Site;
}
set {
base.Site = value;
if (value?.Container is IDesignerHost dh &&
dh.TransactionDescription == "Paste components") {
MessageBox.Show("Pasted");
}
}
}
But probably the transaction description is localized, because it is the text that you see in the drop-down of the Undo button on the toolbar of Visual Studio after having pasted the component.

Telerik UI For WinForms RadMessageBox font size

Is there a way to increase the default font size of the RadMessageBox for the whole application without having to create a custom theme?
If not, how to just increase the font on the default theme in Visual Style Builder? I tried just increasing the label and button font sizes, but the style builder reset the whole form that hosts the message box to look very plain and cutting the text of the label (see attached screenshot).
Thank you.
It is possible to customize the font for all RadMessageBoxes within an application.
Implement a method ('SetTelerikControlStyles') which is called before any form and/or RadMessageBox is created. You only need to call this method once!
Add the following lines of code in the created method of step 1:
RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);
RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
The FormElement.TitleBar.Font, as the name already reveals, is the title bar of the RadMessageBox.
Telerik is using dynamic named controls, so in this case radLabel1 represents the RadMessageBox text area.
Complete Program.cs sample:
using System;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls;
namespace WindowsFormsApplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SetTelerikControlStyles();
Application.Run(new Form1());
}
private static void SetTelerikControlStyles()
{
RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);
// I added this additional check for safety, if Telerik modifies the name of the control.
if (RadMessageBox.Instance.Controls.ContainsKey("radLabel1"))
{
RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
}
}
}
}

Crash for second view object's name assign

I am new to Xamarin and MVVMCross. So I have created 2 views. Login and Register. I have a button on Login to goto Register view and I am going there by this code in the Login's ViewModel:
// method when user tap register button
public IMvxCommand NavigateRegister
{
get { return new MvxCommand(() => ShowViewModel<RegisterViewModel>()); }
}
It works ok the Register Page opens well. But once I assign Name for a single object on Register view (a textEdit), the app crash when I tap on the Register button.
Below is the error msg:
Xamarin.iOS: Received unhandled ObjectiveC exception:
NSUnknownKeyException [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key regNameEdit.
EDIT:
More details: I already assigned the name (see pic below), but still crash:
And the view also been assigned to its Class "CreateAccount". But I am noticing the class declaration has "partial" darkened out in the "public partial class CreateAccount : MvxViewController" line. That's the only noticeable difference btw this class and the first one.
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
namespace MyApp.iOS.Views
{
public partial class CreateAccount : MvxViewController
{
public CreateAccount() : base("CreateAccount", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
Title = "Register";
var set = this.CreateBindingSet<CreateAccount, Core.ViewModels.CreateAccountModel>();
set.Bind(regNameEdit).To(vm => vm.NameStr);
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
The Bind(regNameEdit) also is an error (not detecting the textedit still)
This usually means that the a control is not defined in the View/ViewController class in your case the regNameEdit.
Make sure you created the back Property for this Edit and that the class assigned to the XIB is the one containing this property.
If you are using Xamarin Studio Designer you create the back property selecting the UIControl in the XIB/StoryBoard and setting a name, then enter.
This will create a property with the name you specified accessible in the ViewController.
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.MyUITextField.Text = string.Empty;
}
UPDATE
When using Storyboard:
Try this: Remove the name from the TextField and also remove the name from the ViewController class, then clean your project and rebuild. Re-add the class to the ViewController but when doing it click over the yellow icon in the bottom, there put the name and hit enter. Continue with the TextField, select it put the name and hit enter.
UPDATE # 2
When using XIBs
When you create the ViewController from the menu, Xamarin Studio will create both the ViewController class and the XIB file and will associate one with the other so here you don't have to do anything else to link them.
For the TextField you will need to do it adding the name as previously indicated.
Try this: Remove the name of the UITextField and save and clean/rebuild the project then add the name and hit enter.
Something you can do to verify if there's any problem, double click on the button in the XIB and this should take you to the ViewController class to create a method.
Hope this helps.

Change icon on button in scout eclipse

I would like to implement some think like toggle button in scout eclipse.
What I need is to change image of button for state.
I see function
setIconId(String)
but I dont know how to find parameter for this function. How to find image that scout use for different state of button?
Marko
setIconId(..) and Icons
It is a good practice in your Scout Application to pass as Argument from setIconId(..) a constant defined in the Icons Class. See Icons page on the wiki.
An example for your use case:
setIconId(Icons.WeatherSun)
In the Demo Widget Application there is an Icons class:
org.eclipsescout.demo.widgets.shared.Icons
Here some constants defined in this class:
public static final String WeatherRain = "weather_rain";
public static final String WeatherSnow = "weather_snow";
public static final String WeatherSun = "weather_sun";
The values defined in the constants represent an identifier for the image.
The Image lookup is realized by the ImageLocator. (Depending on the UI technology, the appropriate IconLocator will be used. For example, in case of Swing the SwingIconLocator implementation).
In case of weather_sun the default implementation of the ImageLocator will look for a File called weather_sun.<ext> (where <ext> can be gif, png and so on) in the \resources\icons\ folder of each plugins. In this case it will find the File: \org.eclipsescout.demo.widgets.client\resources\icons\weather_sun.png
If the image is not found, you will see a log entry like this:
!MESSAGE org.eclipse.scout.rt.ui.swing.SwingIconLocator.warnImageNotFound(SwingIconLocator.java:141) could not find image 'weather_sun'
In the Scout SDK, there is an Icons Editor. This Editor represents all the constants defined in the Icons class and the corresponding Icon. Is a file not found a red square is displayed instead of the image.
Toggle Button
There is no specific field for Toggle Button, use an AbstractButton an set the display style to DISPLAY_STYLE_TOGGLE.
See also:
10.8 - Buttons and Links in the Scout Boook.
ToggleButton wiki page.
Changing the icon in a Toogle Button
I think this code snippet does what you are looking for:
#Order(10)
public class ToggleButton1 extends AbstractButton {
#Override
protected boolean getConfiguredProcessButton() {
return false;
}
#Override
protected void execClickAction() throws ProcessingException {
if (isSelected()) {
setIconId(Icons.WeatherSun);
}
else {
setIconId(Icons.WeatherRain);
}
}
}
It would also be possible (and even better) to use execToggleAction instead of execClickAction.
Screenshot:

using html.actionlink outside of a viewpage in MVC3

Struggling on in my first MVC project, I need to show a menu of steps for a wizard. The problem is that some of the steps depend on the data that the user provides.
So say for example, if a user pays cash, we skip the page that shows bank-account information (and thus remove the menu-item)..
I have a "page" class in C#, and a "menu" class that has a list of "pages". I'm going to write the logic that dictates whether or not to show a menu-item in the menu class.
The problem is this;
The page class is a very simple class that looks like this ("active" means the menuitem is highlighted as the currently active item):
public class Page
{
MvcHtmlString Link { get; set; }
bool Active { get; set; }
bool Visible { get; set; }
public Page(MvcHtmlString link)
{
Link = link;
Active = false;
Visible = true;
}
public Page(MvcHtmlString link, bool active, bool visible)
{
Link = link;
Active = active;
Visible = visible;
}
}
In my logic I want to add pages to the list, and I'd like to use the "Link" property of a page to store the target URL for each menu-item. This way I can fill that property using Html.Actionlink() and all its available parameters to generate the HTML for the link.
In the eventual menu I can just iterate and show the items.
It also has the advantage that I could do an AJAX call to this function and receive HTML back I can use in my page to update the menu dynamically.
However, Html.ActionLink is not available, and in other posts on Stackoverflow I found that people also dislike using a html helper outside of an MVC view, for understandable reasons.
So my question is; how would I go about this in a clean solution? I considered giving the page class not a Link property, but "controller" and "action" properties, but I would be missing out on the flexibility of adding a class or other HTML attributes easily, which the actionlink DOES provide.
Thanks,
Erik

Resources