18 new messages in 15 topics - digest

==============================================================================
TOPIC: Retrieving Unique Items from a List
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/42b1bbc264a5b81b?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 6:41 pm
From: "Peter Duniho"


On Thu, 15 May 2008 15:40:02 -0700, amir <amir@discussions.microsoft.com>
wrote:

> [...]
> foreach (item in the list)
> mylist = list.findall(item);
> foreach(myitem in mylist)
> dosomething
>
> the problem occurs in the outer foreach where it already has processed
> some
> items from the original list. how do i exclude them?

If you really must process your list items in groups according to your
FindAll() results, I think using LINQ as Tim suggests would work well.
However, I have to wonder why you want to do this. Nothing in the code
you posted indicates an actual need to do this, and it seems like you'd be
better off just enumerating the list and processing each element one by
one. The way you've shown it, you've basically got an O(N^2) algorithm
even if we assume you somehow address the duplicated item issue at no cost
(which isn't a realistic assumption).

If you can't use LINQ and you must process in groups, an alternative
solution would be to use a Dictionary where the key for the dictionary is
the same as whatever criteria you're using for the FindAll() search.
Then, when enumerating each item in the list, rather than doing work
during that enumeration, simply build up lists of elements in your
Dictionary based on that key, and then enumerate those lists later:

Dictionary<KeyType, List<ListItem>> dict = new Dictionary<KeyType,
List<ListItem>>();

foreach (ListItem item in list)
{
List<ListItem> listDict;

if (!dict.TryGetValue(item.KeyProperty, out listDict))
{
listDict = new List<ListItem>();
dict.Add(item.KeyProperty, listDict);
}

listDict.Add(item);
}

foreach (List<ListItem> listItems in dict.Values)
{
foreach (ListItem item in listItems)
{
// do something
}
}

That's only O(N) instead of O(N^2) and IMHO makes it a bit more clear that
you specifically are trying to group the items before processing.

Pete

==============================================================================
TOPIC: When is Winforms Combobox.SelectedValue a string?
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/18da1ad11f4631d4?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 6:42 pm
From: ".\\\\axxx"


From memory, you'll get this sort of behaviour when you have no
datasource (i.e. it either hasn'e been set or is set to null) - so I
would check that your BindeNumToList is working properly,


On May 16, 5:08 am, Ethan Strauss
<EthanStra...@discussions.microsoft.com> wrote:
> Hi,
> I generally work on web apps, but I am dealing with a Winform right now
> and may be missing something really basic.
> I have a combobox and I would like to know what value has been selected.
> When I try to get the value as a string I sometimes get errors because
> Combobox.SelectedValue is a DataRowView and when I try to get the value by
> first casting as a DataRowView I sometimes get errors because I can't cast a
> string to a DataRowView! I have not been able to track down when the value is
> what and, while I could check for type, that seems really cumbersome for just
> getting a simple value! Anyone know what I am missing?
> More details: The combobox starts life without any items. It gets a
> datatable as a datasource when the Tab of a Tabcontrol, on which it resides,
> is selected. The databinding looks like this:
>
> public static void BindeNumToList(System.Windows.Forms.ListControl
> theControl, Type EnumType)
> {
> theControl.DataSource = eNumByDescriptionAsDataTable(EnumType);
> theControl.DisplayMember = "Displays";
> theControl.ValueMember = "Values";
> }
>
> where eNumByDescriptionAsDataTable is a method which generates a simple
> datatable with a "Values" column and a "Displays" column from an eNum type.
>
> The code which tries to find the value of the combobox looks like this:
> DataRowView SelectedRow = (DataRowView)KitUsedBox.SelectedValue;
> KitUsed TheKit = (KitUsed)int.Parse(SelectedRow[0].ToString());
> // KitUsed TheKit =
> (KitUsed)int.Parse(KitUsedBox.SelectedValue.ToString());
>
> The uncommented part sometimesworks and sometimes throws errors. When I
> switch and just have the part the is currently commented, I get the same
> general behavior. Sometimes works, sometimes throws errors.
>
> Thanks for your help!
> Ethan
>
> Ethan Strauss Ph.D.
> Bioinformatics Scientist
> Promega Corporation
> 2800 Woods Hollow Rd.
> Madison, WI 53711
> 608-274-4330
> 800-356-9526
> ethan.strauss atsign promega.com


==============================================================================
TOPIC: What's the @ operator do?
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/893a68d68fe33f39?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 6:45 pm
From: ".\\\\axxx"


On May 16, 2:16 am, stork <tband...@storkyak.com> wrote:
> If I see a piece of code like:
>
> someobject.stringProperty = @mycontrol.Text;
>
> What does the @ do in that case?
>
> Is that a clone operator?

The prefix "@" enables the use of keywords as identifiers, which is
useful when interfacing with other programming languages. The
character @ is not actually part of the identifier, so the identifier
might be seen in other languages as a normal identifier, without the
prefix. An identifier with an @ prefix is called a verbatim
identifier. Use of the @ prefix for identifiers that are not keywords
is permitted, but strongly discouraged as a matter of style.
From MSDN
http://msdn.microsoft.com/en-us/library/aa664670(VS.71).aspx

==============================================================================
TOPIC: invisible gui
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/66f42bb971d1705c?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, May 15 2008 7:14 pm
From: "Dave"


You misunderstood, I mentioned the progress bar as a reason to why I wanted
to see the form before processing begins. You CAN NOT see the progress bar
on startup.The files are processed correctly even though you can't see the
progress.

I beleive the OnShown() will do what I need. Can you post a short example on
how to use this?

Thanks,

Dave.

"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> wrote in message
news:op.ua7224bc8jd0ej@petes-computer.local...
> On Thu, 15 May 2008 18:01:25 -0700, Dave <DWeb@newsgroup.nospam> wrote:
>
>> I have a program that process files on a hard drive. Everything works
>> fine,
>> it shows a progress bar as it processes the file. The problem occurs
>> when I
>> have the program look for files to process on startup. The gui is
>> invisible
>> untill it processes the files it finds as it startsup. After which it
>> appears and everything works normally when the next file needs to be
>> processed.
>>
>> Is there anyway to tell the program to not look for files untill the
>> interface is visible? I need a method like onGUIAppears.
>
> It's difficult for me to understand how your GUI can show progress if the
> processing begins after the GUI is shown, but not before. Perhaps you've
> made a mistake in your initialization by starting the processing before
> some specific initialization within the GUI is done. The question of
> visibility shouldn't matter.
>
> That said, you can override OnShown() in your form class to know when the
> form is actually being shown and delay your processing until that point.
>
> Pete


== 2 of 2 ==
Date: Thurs, May 15 2008 8:19 pm
From: Mach58


On Thu, 15 May 2008 22:14:31 -0400, "Dave" <DWeb@newsgroup.nospam>
wrote:

>You misunderstood, I mentioned the progress bar as a reason to why I wanted
>to see the form before processing begins. You CAN NOT see the progress bar
>on startup.The files are processed correctly even though you can't see the
>progress.
>
>I beleive the OnShown() will do what I need. Can you post a short example on
>how to use this?
>
>Thanks,
>
>Dave.

Something like this should do:

using System;
using System.Windows.Forms;

class Class1 : Form
{
bool firsttime = true;
protected override void OnShown(EventArgs e)
{
if (firsttime)
{
firsttime = false;
// ##put your code here##
MessageBox.Show("I've been shown! (for the first time)");
}
base.OnShown(e);
}
static void Main(string[] args)
{
Application.Run(new Class1());
}
}

If you need more help, you'll need to post some code. Please follow
this guidelines:

http://www.yoda.arachsys.com/csharp/complete.html

Mach

==============================================================================
TOPIC: binary writes
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/2011bc7d9278584a?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, May 15 2008 7:41 pm
From: Family Tree Mike


%c to me, means character, so I don't know if you wanted to convert the ints
to char for some reason. I went with the ints being ints.

int m = 50;
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);

for (int x = 0; x < m; ++x)
{
for (int y = 0; y < m; ++y)
{
for (int z = 0; z < m; ++z)
{
bw.Write(x); bw.Write(y); bw.Write(z);
}
}
}

File.WriteAllBytes(
@"c:\Software Development\Output.bin",
ms.ToArray());


"sillyhat@yahoo.com" wrote:

> Hello,
>
> Can someone please help.
>
> I want to do some binary writing to files either using sdtout or by
> passing a filename and I am unsure how to do either in C# - I would
> like it to be as fast as possible.
> I have done it in awk, just to see what I mean since the code should
> be understandable by a C# whiz.
>
> Thanks for all constructive help given.
>
> Hal
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ### this is in awk, run using 'awk -f thisfile.awk' > somefile
> BEGIN {
> m=50
>
> for (x=0; x<m; x++)
> for(y=0; y<m; y++)
> for(z=0; z<m; z++)
> printf("%c%c%c",x,y,z)
> }
>


== 2 of 3 ==
Date: Thurs, May 15 2008 7:46 pm
From: Arne Vajhøj


sillyhat@yahoo.com wrote:
> I want to do some binary writing to files either using sdtout or by
> passing a filename and I am unsure how to do either in C# - I would
> like it to be as fast as possible.
> I have done it in awk, just to see what I mean since the code should
> be understandable by a C# whiz.

System.IO.BinaryWriter

Arne


== 3 of 3 ==
Date: Thurs, May 15 2008 10:21 pm
From: Jon Skeet [C# MVP]


<sillyhat@yahoo.com> wrote:
> Can someone please help.
>
> I want to do some binary writing to files either using sdtout or by
> passing a filename and I am unsure how to do either in C# - I would
> like it to be as fast as possible.

In .NET, the console (i.e. stdout) is inherently *text*-based. There
may be a way of reliably writing binary data to a redirected file, but
I don't know it offhand.

For a normal file, just use FileStream - the utility methods in the
File class are also handy.

--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com

==============================================================================
TOPIC: Read MS Access
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/dc5db64c760e0fce?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 7:51 pm
From: Arne Vajhøj


S Chapman wrote:
> What is the quickest way to read Microsoft Access Tables? Right now I
> am using OleDBCommand in C# to read Access but I was wondering if
> there is a quicker way of reading the contents of Access Tables? Thank
> you.

I don't think so.

The only two providers capable of reading MDB's are OleDb and Odbc.

I am pretty sure that OleDB is faster than Odbc.

All other data access methods build on top of one of those and can
therefor not be faster.

Arne

==============================================================================
TOPIC: One significant figure in C#
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/def09c06ddef6c23?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 8:03 pm
From: Arne Vajhøj


mrshrinkray@googlemail.com wrote:
> I feel a bit ashamed asking this after 6 years of C#, but is there a
> format string for significant figures before the decimal place?
>
> e.g.
> 2,354,856:
> 1 sf = 2,000,000
> 2 sf = 2,400,000
> 3 sf = 2,350,000
>
> {0:G} or g gives me scientific notation, but I'm after the above.

I don't think so.

You will need to code it yourself.

One way:

public static string SpecialFormat(int v, int sf)
{
int k = (int)Math.Pow(10, (int)(Math.Log10(v) + 1 - sf));
int v2 = ((v + k/2) / k) * k;
return v2.ToString("0,0");
}

(the calculation of k can be optimized if speed is critical)

Arne


==============================================================================
TOPIC: Reading XML Files
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/6eca51c202d23a2f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 9:17 pm
From: pkenderdine@gmail.com


On May 14, 5:32 pm, Chris Nahr <dioge...@kynosarges.de> wrote:
> You're opening 5,000+ XML files, parsing them, validating them against
> a schema, and storing the results in a dataset... sounds like a lot of
> work to me. Depending on your system that might well take several
> minutes. I don't think there's a way to greatly speed up this job.
> --http://www.kynosarges.de

I have managed to reduce my 3 minutes to 17 seconds. I read in all the
xml files one at a time, output a temporary xml file containing all
the xml. I then read that file into my dataset.

Regards
Phil

==============================================================================
TOPIC: Visual Studio & .NET Framework Product Feedback RSS
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/d2046bc78d210857?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 9:35 pm
From: "Hiroaki SHIBUKI"


Hi,

I began to feed

Visual Studio & .NET Framework Product Feedback RSS:
http://hidori.jp/rss/msconnect/GetRSS.aspx?forum=visualstudio

Enjoy!

--
Hiroaki SHIBUKI
http://hidori.jp/
Microsft MVP for Development Tools - Visual C#


==============================================================================
TOPIC: XML Serialization and Internationalization
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/d9839c1ecd6e8061?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 10:11 pm
From: Nishant Mehta


Hi all,

I am serialiizing a c# object to an XML file to save some application
settings. The idea is to ship this xml file along with the application
and deserialize after the application is installalled to use it as a
default settings file. Works fine on machines having the same culture
(en-US) settings. But goes wrong when the object is serialized on a
machine with the culture set to english and and deserialized on
another machine with another culture (it-IT Italy). For this case I
can see that the problem is that in Italy the decimal seperator is a
comma (,) instead of a dot(.) so deserializing ints and doubles
creates a mess.

So my question is, what is the correct way of handling xml
serialization and globalization?

Any help is most appreciated.

Nishant


==============================================================================
TOPIC: Get System Icon for any file/folder
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/55ba4859298e0e6e?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 9:50 pm
From: v-wywang@online.microsoft.com ("Wen Yuan Wang [MSFT]")


Hello Ashutosh,

Thanks for your reply and screen-shooting. It seems like a black shadow. By
default, ColorDepth property of ImageList is 8 Bit. To display tansparent
color, we would have to change it to 32 bit. Have you ever changed the
colorDepth of ImageList to 32 bit in Code or in Designer Mode?
Eg: imageList1.ColorDepth = ColorDepth.Depth32Bit;

On my side, I reproduced the issue after I change ColorDepth of ImageList
back to 8 bit.

Hope this helps, please try the above method and let me know if this works.
We are glad to assist you.

Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


==============================================================================
TOPIC: Need some help for sending custom commands from ASP.NET page
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/093562aae64310e4?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 10:57 pm
From: erbilkonuk


Hi everyone,
I have been developing a project that is composed of one windows
service and one ASP.NET web site. The windows service and ASP.NET web
site reside on the same server.
I want to send start/stop service commands and custom commands to the
Windows service from ASP.NET Web site.
What I have done is :

* I read in a site that an web site user get credential of a user
"Network Service" at the server so I run the service with account
"Network Service"
* I give full control for user "Network Service" on Windows Service
executable .


What I get at the web site when I try to start/stop Service or send
custom commands is "access denied' error.


Should I programmatically get any priviledges? What should I do?


Best regards


B. Erbil KONUK

==============================================================================
TOPIC: Control MetaData
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/40f44a0034bab95f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 11:07 pm
From: RajkiranPro


Is There A Way To Change The Default Properties Of the Controls

For Example

If we place a button on on the form its default name is button1 and
if we place the next button its button2 and so on..

Instead i want it to be btn1, btn2, btn3 by default...

I know to create it by using a component class

namespace System.Windows.Forms
{
public class btn : System.Windows.Forms.Button
{

private System.ComponentModel.IContainer components = null;

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}

public btn()
{
InitializeComponent();
}

public btn(IContainer container)
{
container.Add(this);

InitializeComponent();
}

}

}


However I want to change this without creating a new class for it..

Is there a way to do this by editing the meta data..

if yes wats the procedure..


Thanks In Advance

Regards
Rajkiran


==============================================================================
TOPIC: Style trigger not firing in wpf app
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d677c0e3747bc15?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, May 15 2008 11:47 pm
From: "moondaddy"


Your suggestion works. Thanks!

"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:09aaosBtIHA.4284@TK2MSFTNGHUB02.phx.gbl...
> Hi Moondaddy,
>
> After doing some research, I figure the problem out.
>
> The main point is that the DataTrigger you use in the
> "ConnectionGroupStyle" is not correct. You should use the relative source
> mode of FindAncestor to get notified when the IsMouseOver property of the
> parent element of the ChildControl changes.
>
> In addition, in the SomeControl.xaml file, you shouldn't set the
> Visibility
> property explicitly because it will override the style that is applied to
> the element. You should set the initial value of the Visibility property
> in
> the style.
>
> The modifications are as follows.
>
> 1. In the Dictionary1.xaml:
>
> <ResourceDictionary
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> xmlns:c="clr-namespace:StyleTriggerFromParent">
>
> <Style x:Key="ConnectionGroupStyle" TargetType="{x:Type
> c:ChildControl}">
> <Setter Property="SnapsToDevicePixels" Value="false"/>
> <Setter Property="Visibility" Value="Hidden"/>
> <Style.Triggers>
> <DataTrigger Value="True">
> <DataTrigger.Binding>
> <Binding Path="IsMouseOver">
> <Binding.RelativeSource>
> <RelativeSource Mode="FindAncestor"
> AncestorType="{x:Type FrameworkElement}" AncestorLevel="1"/>
> </Binding.RelativeSource>
> </Binding>
> </DataTrigger.Binding>
> <Setter Property="Visibility" Value="Visible" />
> </DataTrigger>
> </Style.Triggers>
> </Style>
>
> </ResourceDictionary>
>
> 2. In the SomeControl.xaml, remove the Visibility property from the
> ChildControl element.
>
> Please try my suggestion and let me know the result.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>

==============================================================================
TOPIC: How to add a path inside of a border using c# and wpf
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/6c32aa3e9052727f?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, May 16 2008 12:03 am
From: "moondaddy"


This was a big help as it shows me how to set different styles from
resources in c#. Now I need to change a control template in c#. Is this
possible? If so, then here's a control template applied in xaml:

<ContentControl x:Name="ConnectorGraph" Template="{DynamicResource
ShapeConnectorTemplate}" RenderTransformOrigin="0.5,0.5"
HorizontalAlignment="Right" VerticalAlignment="Center" Width="7"
Height="12" >


and I want to be able to change the template to xyzTemplate using c#.

If this is not allowed, then here's my problem. I have a content control
called "ShapeConnector" which uses a template to create a path in side of
it, and a gradient fill inside that path. The data trigger changes the
color of the fill when the IsMouseOver property changes. this is good.
however, when I'm doing a drag operation the IsMouseOver property doesn't
fire. So I need to manually change the gradient fill in the path. I was
going to do this from a HitTest method in the drag operation and when the
HitTest finds the ShapeConnector content control, I would then change the
fill color there.

One option might be to have a style for the gradient in the path, but I
don't know how to reference a style inside a template using c#. Here's the
xaml for the template:

<ControlTemplate x:Key="ShapeConnectorTemplate" TargetType="{x:Type
ContentControl}" >
<Path x:Name="MyPath" Style="{DynamicResource ConnectorPathStyle}"
RenderTransformOrigin="0.5,0.5" Height="12" Width="7" >
<Path.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0.181,0.5">
<GradientStop Color="#FF82D7EE" Offset="1"/>
<GradientStop Color="#FFFBFFFF" Offset="0.237"/>
</LinearGradientBrush>
</Path.Fill>
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,0" IsClosed="True">
<BezierSegment Point1="8,6" Point2="8,6"
Point3="0,12"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<ControlTemplate.Triggers>

<DataTrigger Value="True">
<DataTrigger.Binding>
<Binding Path="IsMouseOver">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor"
AncestorType="{x:Type FrameworkElement}" AncestorLevel="1"/>
</Binding.RelativeSource>
</Binding>
</DataTrigger.Binding>
<Setter Property="Fill" TargetName="MyPath">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0.5"
StartPoint="0.181,0.5">
<GradientStop Color="#FFF7B030" Offset="0.835"/>
<GradientStop Color="#FFFFFDF6" Offset="0.058"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>


I'm thinking I wound need to chang the stype for "MyPath" in this line:

x:Name="MyPath" Style="{DynamicResource ConnectorPathStyle}"

but using c#.

What do you recomend?


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:yFbBZHmtIHA.4284@TK2MSFTNGHUB02.phx.gbl...
> Hi Moondaddy,
>
>>I need to dynamically add these content controls using c# at runtime and
> am having trouble referencing the styles and adding the path into the
> border.
>
> To retrieve resources in code, call the FrameworkElement.FindResource or
> TryFindResource method.
>
> The following is a sample to add the ContentControl named "btnOtM" to the
> Canvas in code. It requires to set the Name attribute in the Canvas
> element
> to "Canvas1" in your sample XAML snippet.
>
> private void Window_Loaded(object sender, RoutedEventArgs e)
> {
> // build a ContentControl
> ContentControl cc = new ContentControl();
> cc.Name = "btnOtM";
> cc.Width = 11;
> cc.Height = 10;
> Canvas.SetLeft(cc, 12);
> Canvas.SetTop(cc, 25);
>
> // build a Border
> Border b = new Border();
> b.Style =
> TryFindResource("FunctionConnectorSelectorButtonStyle") as Style;
>
>
> // build a PathGeometry
> Path p = new Path();
> p.Stroke = new
> SolidColorBrush(Color.FromArgb(0xFF,0,0x71,0x82));
> p.StrokeThickness = 1;
> PathGeometry pg = new PathGeometry();
> PathFigure pf = new PathFigure();
> pf.StartPoint = new Point(2, 2);
> pf.Segments.Add(new LineSegment(new Point(5, 2),true));
> pf.Segments.Add(new LineSegment(new Point(5, 6), true));
> pf.Segments.Add(new LineSegment(new Point(2, 6), true));
> pg.Figures.Add(pf);
>
> pf = new PathFigure();
> pf.StartPoint = new Point(5, 4);
> pf.Segments.Add(new LineSegment(new Point(8, 4), true));
> pg.Figures.Add(pf);
> p.Data = pg;
>
> b.Child = p;
> cc.Content = b;
> this.Canvas1.Children.Add(cc);
> }
>
> Hope this helps.
> If you have any question, please feel free to let me know.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>

No comments: