开发者

Data Binding Dissimilar Types

Trying to accomplish:

I want to change the image property of a bound tree node when the value of an enumerated property changes on the bound object.

Bound Object is representation of an airfield or vehicle base in a game. The object has a property of Type which is an enumerated value type: SmallAirfield, MediumAirField, LargeAirField, Port, AirCraftCarrier

The object bein开发者_Go百科g inspected is displayed and edited in a property grid...

The extended/node in the tree exposes an Image Property

When the user changes the enumerated value of the Type of base this is...I want to update the image of the tree node...

Thus, I am trying to bind dissimilar value types...

In other words, if the user changes the airbase type to aircraft carrier, I want to change the little image to the aircraft carrier image...

I do not want to include/expose an image property in the object representation of airbase object...

How can I bind the image property of type Image to my enumerated airfield Type property of the airfield object?

I hope that makes sense?

Carson


foreach (Field f in fields) {

if (f.CurrentOwner == country)
{

    addNode = node.Add(node.Key + f.ID, f.ID);
    addNode.Tag = f;
    addNode.DataBindings.Add("Text", f, "ID");
    /// HERE IS WHERE I WOULD BIND THE IMAGE OF THE NODE TO THE 
    /// TO TYPE OF FIELD....
    switch (f.Type)
    {
        case BaseType.Airfield:
            fieldNode.Image = ((Icon)Scenario.Properties.Resources.Pony).ToBitmap();
            break;
        case BaseType.Carrier:
            fieldNode.Image = ((Icon)Scenario.Properties.Resources.CV).ToBitmap();
            break;
        case BaseType.Port:
            fieldNode.Image = ((Icon)Scenario.Properties.Resources.Tiger).ToBitmap();
            break;
        case BaseType.VBase:
            fieldNode.Image = ((Icon)Scenario.Properties.Resources.Tiger).ToBitmap();
            break;
    }
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜