|
I want to create a WPF dll( assembly),so that I can use it in some other C# or VC++ application.
Please help.
|
|
|
|
|
Why does it have to be a WPF dll, the only reason to use WPF is for the UI, probably not valid to use such a DLL in c++.
Otherwise just create a WPF library application.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You will have to describe what you want your assembly to contain before you get a definitive answer. There are a number of assumptions that I could make about what you want here that possibly wouldn't be valid. For instance, do you want it to contain WPF screens? Does it just need to be the data and business logic?
This space for rent
|
|
|
|
|
Open VS.
Either open your existing solution and use the Solution Explorer pane to add a new project, or create a new project.
Select the "Visual C#" ... "Windows Desktop" project types from the menu on the left of the New Project dialog.
In the middle panel, select "WPF User Control Library"
Give it an appropriate name.
Press OK.
Now you can create the controls and code for your Assembly.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I want a cup of coffee so I can drink it...
Please help.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
here it is ...
|
|
|
|
|
I'm working on a type converter for .Net to Sql and .Net to OleDb.
First, I create a class called DataType:
public class DataType
{
public DotNetTypes? DotNetType { get; private set; }
public SqlDbType? SqlDbType { get; private set; }
public OleDbType? OleDbType { get; private set; }
public DataType(DotNetTypes? dotNetType, SqlDbType? sqlDbType, OleDbType? oleDbType)
{
DotNetType = dotNetType;
SqlDbType = sqlDbType;
OleDbType = oleDbType;
}
}
Next I load it like this:
private static List<DataType> DataTypes;
static DataTypeConversion()
{
Load();
}
private static void Load()
{
DataTypes = new List<DataType>
{
new DataType(DotNetTypes.Short, SqlDbType.SmallInt, null),
new DataType(DotNetTypes.Int32, SqlDbType.Int, null),
new DataType(DotNetTypes.Int64, SqlDbType.BigInt, null),
new DataType(DotNetTypes.Boolean, SqlDbType.Bit, null),
new DataType(DotNetTypes.Double, SqlDbType.Float, null),
new DataType(DotNetTypes.Float, SqlDbType.Real, null),
new DataType(DotNetTypes.Guid, SqlDbType.UniqueIdentifier, null),
new DataType(DotNetTypes.Byte, SqlDbType.TinyInt, null),
new DataType(DotNetTypes.DataTable, SqlDbType.Structured, null),
new DataType(DotNetTypes.DateTime, SqlDbType.DateTime, null),
new DataType(DotNetTypes.DateTime, SqlDbType.SmallDateTime, null),
new DataType(DotNetTypes.DateTime, SqlDbType.Date, null),
new DataType(DotNetTypes.DateTime, SqlDbType.Time, null),
new DataType(DotNetTypes.DateTime, SqlDbType.DateTime2, null),
new DataType(DotNetTypes.DateTimeOffset, SqlDbType.DateTimeOffset, null),
new DataType(DotNetTypes.Object, SqlDbType.Variant, null),
new DataType(DotNetTypes.Object, SqlDbType.Udt, null),
new DataType(DotNetTypes.Decimal, SqlDbType.Decimal, null),
new DataType(DotNetTypes.Decimal, SqlDbType.Money, null),
new DataType(DotNetTypes.Decimal, SqlDbType.SmallMoney, null),
new DataType(DotNetTypes.Byte, SqlDbType.Binary, null),
new DataType(DotNetTypes.Byte, SqlDbType.Image, null),
new DataType(DotNetTypes.Byte, SqlDbType.VarBinary, null),
new DataType(DotNetTypes.Byte, SqlDbType.Timestamp, null),
new DataType(DotNetTypes.String, SqlDbType.NVarChar, null),
new DataType(DotNetTypes.String, SqlDbType.VarChar, null),
new DataType(DotNetTypes.String, SqlDbType.Char, null),
new DataType(DotNetTypes.String, SqlDbType.NChar, null),
new DataType(DotNetTypes.String, SqlDbType.NText, null),
new DataType(DotNetTypes.String, SqlDbType.Text, null),
new DataType(DotNetTypes.String, SqlDbType.Xml, null)
};
}
To do this I created an enum called DotNetTypes:
public enum DotNetTypes
{
@Unknown,
@Short,
@Boolean,
@Byte,
@Char,
@DateTime,
@DateTimeOffset,
@Decimal,
@Double,
@Int32,
@Int16,
@Int64,
@Float,
@Object,
@SByte,
@Single,
@String,
@UInt16,
@UInt32,
@UInt64,
@Guid,
@DataTable
}
Notice that in the Load method I have
new DataType(DotNetTypes.Byte, SqlDbType.Binary, null),
new DataType(DotNetTypes.Byte, SqlDbType.Image, null),
new DataType(DotNetTypes.Byte, SqlDbType.VarBinary, null),
new DataType(DotNetTypes.Byte, SqlDbType.Timestamp, null),
The problem is that these should be byte arrays, not byte. So what is the syntax for this in my DotNetTypes enum?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
DotNetTypes.ByteArray ?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
ByteArray is not a valid .Net data type. The items in my enum are. The question is how to define one that makes it array.
With the .Net types:
System.Int16
System.Int32
System.Int64
in my enum those are
@Int16,
@Int32,
@Int64
The compiler recognizes those are valid .Net types. So for
System.Byte
How do you add an enum for byte[]? Byte and Byte[] are not the same.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: ByteArray is not a valid .Net data type. The items in my enum are. The question is how to define one that makes it array. No - the items in your enum aren't types either. They just bear the same name and that's why the grammar of C# requires you to prefix them with an @ . You don't gain anything by doing that.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hey guys.
I'm struggling to use a REST API. My Problem is that only available documentation for this API is too old and it is not supported in newer versions of .net
Please help me to convert it, here is the documentation:
using (var client = new HttpClient("http://rt.site.com/REST/1.0/"))
{
client.TransportSettings.Cookies = new CookieContainer();
var form = new HttpUrlEncodedForm();
form.Add("user", "LOGIN");
form.Add("pass", "PASSWORD");
client.Post(string.Empty, form.CreateHttpContent());
using (var request = client.Get("ticket/1234/show"))
{
string content = request.Content.ReadAsString();
}
var formPost = new HttpMultipartMimeForm();
byte[] attachment = new byte[];
string content = string.Empty;
formPost.Add("content", content);
formPost.Add("attachment_1", "attachment_1", HttpContent.Create(attachment, "application/octet-stream"));
using (var post = client.Post("ticket/1234/comment"), formPost.CreateHttpContent()))
}
And here is what I have done so far:
var credentials = new NetworkCredential(name, pass);
CookieContainer CookieContainer = new CookieContainer();
var handler = new HttpClientHandler {CookieContainer = CookieContainer, Credentials = credentials };
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://something.net");
var form = new List<KeyValuePair<string, string>>();
form.Add(new KeyValuePair<string, string>("user", name));
form.Add(new KeyValuePair<string, string>("pass", pass));
var request = new HttpRequestMessage(HttpMethod.Post, "/rt/REST/1.0");
request.Content = new FormUrlEncodedContent(form);
var response = await client.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();
Please note to this comment:
The REST Interface does not support HTTP-Authentication. So you must get a valid Session-Token and submit the cookie each request. You usually get a Session-Cookie by submitting the default login form. Use variables "user" for login and "pass" for password values
Thank you very much
|
|
|
|
|
hi all,
barcode code 128 symbology use modulo 103 for checksum digit.
it has 3 subset A , B C, 103,104 and 105 use respectively to calculate checksum.
what can i use to calculate for code 128 Auto and uss/ean 128?
please help me for this.
thanks in advance.
|
|
|
|
|
|
Code 128 - Wikipedia[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I just started learning Unity a few days ago, and I have found a very helpful tutorial on how to make a game. However, I keep getting this error and I have tried everything to figure out why its occurring. Maybe someone can take a look at the code and help me out? Thanks!
The error is on the line "DialogueSystem.Instance.AddNewDialogue (dialogue);"
And the full error is "No overload for method 'AddNewDialogue' takes '1' arguments"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPC : Interactable {
public string[] dialogue;
public string name;
public override void Interact()
{
DialogueSystem.Instance.AddNewDialogue (dialogue);
Debug.Log ("Interacting with NPC.");
}
}
|
|
|
|
|
Use IntelliSense: Remove and re-type the opening brace after AddNewDialogue and Visual Studio will show you a pop-up with all valid signatures of that method(name). And most likely there actually will be none with only one argument.
If your tutorial suggests otherwise then you're probably missing a using-declaration or an assembly reference. If it's the former then Visual Studio should show a "Quick Actions and Refactorings"-tooltip when hovering over AddNewDialogue that allows you to have the using-declaration added. Otherwise look through the tutorial for instructions on which assemblies to reference.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks! That did the trick
|
|
|
|
|
I'm writing a C# WinForms project that uses DotNetZip. Here's the step-by-step to save a file:
1. Write the file to a temp file using FileStream and BinaryWriter...
glbstrSaveFilePath = strfilepath;
string strTempPath = Path.GetTempFileName();
Path.ChangeExtension(strTempPath, ".bin");
FileStream fs = new FileStream(strTempPath, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(somestring);
bw.Write(someboolean);
bw.Write(someotherstring);
2. Next, I use DotNetZip to compress it and save it to the location from the SaveFileDialog...
using (ZipFile zip = new ZipFile())
{
Path.ChangeExtension(strTempPath, ".bin");
zip.AddFile(strTempPath, "MyProject");
zip.Save(strfilepath);
}
The file seems to be compressing and saving correctly because I can open the resulting file in 7-Zip and then read the "MyProject" file. Everything looks OK.
Here's where the problem occurs. To open the file I do...
1. Extract the file from its location using DotNetZip...
ZipFile zip = ZipFile.Read(strfilepath);
Directory.CreateDirectory(strTempPath);
Path.ChangeExtension(strTempPath, ".bin");
foreach (ZipEntry e in zip)
{
if (e.FileName == "MyProject")
e.Extract(strTempPath, ExtractExistingFileAction.OverwriteSilently);
}
2. Next, I open the temp file (strTempPath) using FileStream and BinaryReader...
FileStream fs = new FileStream(strTempPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
strStringOne = br.ReadString();
blBooleanOne = br.ReadBoolean();
strStringTwo = br.ReadString();
Unfortunately, steps 1 and 2 above don't seem to execute. I'm at a loss to find out why. Is there anything wrong with the code in Step 1?
|
|
|
|
|
I haven't used DotNetZip yet but there are some things catching my eye, the first one most likely being the culprit (even though "don't seem to execute" isn't very specific ).
This:
Path.ChangeExtension(strTempPath, ".bin"); ..does nothing for you. You most probably intended this:
strTempPath = Path.ChangeExtension(strTempPath, ".bin"); Strings are immutable. When using a method that "modifies" a string you always have to use the returned version.
Most probably this line fails then:
e.Extract(strTempPath, ExtractExistingFileAction.OverwriteSilently); ..because strTempPath is still the name of the directory.
Other observations:
You're not enclosing your streams in using -blocks. Probably not the cause of your problem here but I strongly advise you to always do that. I've seen funny things happening when not doing that, which do not always immediately reveal themselves as stream issues and send you on a wild goose chase.
Don't use the same variable once for a directory name and then for a file name. It was confusing to read and I bet it will confuse you too, when you read your code again after doing different stuff for a while.
And a style suggestion: Don't use Systems Hungarian. It's not recommended by Microsoft, for a good reason, I think. If you're interested: Making Wrong Code Look Wrong – Joel on Software[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Also take into account that string strTempPath = Path.GetTempFileName(); creates the file on disc already - you should remove it afterwards.
Or create the temp filename your self, e.g.
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".bin");
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Thank you all for taking your time to help.
Had an issue with adding in music files, now that is resolved. However the path to the music files is in a certain sequence. I tried to move that sequence by using remove and insert however that removes the path to the file so when I click on the file I want to play, it doesn't play. Below is the code I have just for up button. So How can I move an item in the 'path' list to move without removing it?
public partial class JukeBox : Form
{
private readonly List<string> paths = new List<string>();
public JukeBox()
{
InitializeComponent();
}
private void btnFiles_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
paths.AddRange(openFileDialog1.FileNames);
string[] files = openFileDialog1.SafeFileNames;
for (int i = 0; i < files.Length; i++)
{
listBox1.Items.Add(files[i]);
}
}
}
private void btnPlay_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = paths[listBox1.SelectedIndex];
}
private void btnUp_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
object selected = listBox1.SelectedItem;
string lbName = listBox1.GetItemText(listBox1.SelectedItem);
int lbIndex = listBox1.Items.IndexOf(selected);
int lbTotal = listBox1.Items.Count;
int pathIndex = paths.IndexOf(lbName);
if (lbIndex == 0)
{
paths.Remove(lbName);
paths.Insert(lbTotal - 1,lbName);
listBox1.Items.Remove(selected);
listBox1.Items.Insert(lbTotal - 1, selected);
listBox1.SetSelected(lbTotal - 1, true);
}
else
{
paths.Remove(lbName);
paths.Insert(lbIndex - 1, lbName);
listBox1.Items.Remove(selected);
listBox1.Items.Insert(lbIndex - 1, selected);
listBox1.SetSelected(lbIndex - 1, true);
}
}
}
|
|
|
|
|
|
Richard,
The reason for this layout, I've tried a lot of ways to add music files to a listbox than add some more files and they wouldn't play due to out of range error. With this layout it allows me to add music files to my list box and if I want to add some more I can.
Thank you
|
|
|
|
|
Yes, except it still does not work. And if you get of range errors you need to diagnose the problem and fix your code rather than just ignoring it.
|
|
|
|
|
Richard,
Coming to this site doesn't mean that I was ignoring the problem, one cannot complete a task if they ignore the problems. Me coming to this site was me asking for help for an issue that I've been trying to fix for some time. I kindly ask, if you cannot help with the issue please don't reply again.
Thank you
|
|
|
|
|