How can I create a closeable chip on Mudblazor Fileupload Drag&Drop?
Here is an example: https://try.mudblazor.com/snippet/GYwHEQvURJEkHBcX
#inject ISnackbar Snackbar
<MudStack Style="width: 100%">
<MudFileUpload T="IReadOnlyList<IBrowserFile>" OnFilesChanged="OnInputFileChanged" Hidden="false" Class="flex-1" InputClass="absolute mud-width-full mud-height-full overflow-hidden z-20" InputStyle="opacity:0"
#ondragenter="#SetDragClass" #ondragleave="#ClearDragClass" #ondragend="#ClearDragClass">
<ButtonTemplate>
<MudPaper Height="300px" Outlined="true" Class="#DragClass">
<MudText Typo="Typo.h6">Drag and drop files here or click</MudText>
#foreach (var file in fileNames)
{
<MudChip Color="Color.Dark" Text="#file" OnClose="Closed" />
}
</MudPaper>
</ButtonTemplate>
</MudFileUpload>
<MudToolBar DisableGutters="true" Class="gap-4">
<MudButton OnClick="Upload" Disabled="#(!fileNames.Any())" Color="Color.Primary" Variant="Variant.Filled">Upload</MudButton>
<MudButton OnClick="Clear" Disabled="#(!fileNames.Any())" Color="Color.Error" Variant="Variant.Filled">Clear</MudButton>
</MudToolBar>
</MudStack>
#code {
private static string DefaultDragClass = "relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full z-10";
private string DragClass = DefaultDragClass;
private List<string> fileNames = new List<string>();
private void OnInputFileChanged(InputFileChangeEventArgs e)
{
ClearDragClass();
var files = e.GetMultipleFiles();
foreach (var file in files)
{
fileNames.Add(file.Name);
}
}
void Closed(MudChip chip) {
fileNames.Remove(chip.Text);
}
private async Task Clear()
{
fileNames.Clear();
ClearDragClass();
await Task.Delay(100);
}
private void Upload()
{
//Upload the files here
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
Snackbar.Add("TODO: Upload your files!", Severity.Normal);
}
private void SetDragClass()
{
DragClass = $"{DefaultDragClass} mud-border-primary";
}
private void ClearDragClass()
{
DragClass = DefaultDragClass;
}
}
The chip is not clickable and if I change the Z-Index of the MudFileUpload control it collapses. I also tried to add Z-Index above 20 to the chip but I still cannot click it.
Related
What I'm trying to do in a UWP app with Win2D:
User pressed a button to add an image and picks their file.
That file gets loaded as a resource for a Canvas Control.
The image then gets rendered to the current drawing session
When the button is clicked:
private async void btnAddPicture_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
overlayPictureFile = await picker.PickSingleFileAsync();
if (overlayPictureFile == null)
{
txbNotification.Text = "File Picking cancelled";
return;
}
else
{
txbNotification.Text = "Picture Loaded";
}
using (IRandomAccessStream stream = await overlayPictureFile.OpenAsync(FileAccessMode.Read))
{
var device = new CanvasDevice();
createdBitmap = await CanvasBitmap.LoadAsync(device, stream);
}
}
In the drawing function:
void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
if (createdBitmap != null)
{
args.DrawingSession.DrawImage(createdBitmap, Drawing.FindDefaultRect());
}
drawingCanvas.Invalidate();
}
Everything will compile but the moment I press the button to add an image it breaks here.
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
I'm already loading some image in this, but those are all part of the program and are created before the canvas is created with these. Not sure how to do that with ones the user picks.
private void drawingCanvas_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
{
args.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction());
}
private async Task CreateResourcesAsync(CanvasControl sender)
{
logo = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/Pictures/Logo_BlackBorders.png"));
}
Update:
Where I currently am drawing things. This is the canvas I'm trying to add the image to.
void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
//Drawing a bunch of stuff
}
private void drawingCanvas_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
{
args.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction());
}
private async Task CreateResourcesAsync(CanvasControl sender)
{
logo = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/Pictures/Logo.png"));
}
Load an Image to a Canvas Control from a File Picker
For your scenario, you could get CanvasDrawingSession with CreateDrawingSession method. And then use this drawingsession to draw picked image to current CanvasControl.
For example.
private async void btnAddPicture_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
var overlayPictureFile = await picker.PickSingleFileAsync();
if (overlayPictureFile == null)
{
return;
}
else
{
}
using (IRandomAccessStream stream = await overlayPictureFile.OpenAsync(FileAccessMode.Read))
{
//get canvascontrol's Device property.
CanvasDevice device = drawingCanvas.Device;
createdBitmap = await CanvasBitmap.LoadAsync(device, stream);
//use device property to make renderer
var renderer = new CanvasRenderTarget(device,
createdBitmap.SizeInPixels.Width,
createdBitmap.SizeInPixels.Height, createdBitmap.Dpi);
//make ds with above renderer.
using (var ds = renderer.CreateDrawingSession())
{
ds.DrawImage(createdBitmap, 0, 0);
}
}
}
I'm trying to bind a list of strings to a datalist. I'm trying to do the binding in a controller and the datalist is in a view(chtml file). I keep getting the error : "The name "datalist id" does not exist in the current context".
Any idea how I can fix this issue?
<input list="cardProgram" class="form-control input-group-lg">
<datalist id="cardProgram" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
BindCardPrograms(sender, e);
}
private async void BindCardPrograms(object sender, EventArgs e)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:59066/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
ViewBag.country = "";
HttpResponseMessage response = await
client.GetAsync("api/Profile/InitializeCardProgramSelection");
if (response.IsSuccessStatusCode)
{
List<String> cardPrograms =
response.Content.ReadAsAsync<List<String>>().Result;
var builder = new System.Text.StringBuilder();
foreach (String filename in cardPrograms)
{
builder.Append(String.Format("<option value='{0}'>",
filename));
cardProgram.InnerHtml = builder.ToString();
}
}
/*else
{
return View();
}*/
}
}
I have 2 list views and I'm trying to drag an item from one to the other.
The typeof item is a storagefile.
private async void ListA_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
List<IStorageItem> files = new List<IStorageItem>();
StorageFile file = e.Items;
files.Add(file);
e.Data.SetStorageItems(files);
}
private void ListC_DragEnter(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Copy;
}
private async void ListC_Drop(object sender, DragEventArgs e)
{
//if (e.DataView.Contains(StandardDataFormats.StorageItems))
//{
// var items = await e.DataView.GetStorageItemsAsync();
// if (items.Count > 0)
// {
// var storageFile = items[0] as StorageFile;
// ListC.Items.Add(storageFile);
// }
// }
}
I've tried everything I can think of to drop the storage file into the other listview and show the display name... All I've been able to display are types and stuff.
Can anyone help me?
I've solved it after hours or trying.
private async void ListA_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
//f.MessageBox(e.Items.First().GetType().ToString());
try
{
List<IStorageItem> files = new List<IStorageItem>();
StorageFile file = e.Items.First() as StorageFile;
files.Add(file);
e.Data.SetStorageItems(files);
//e.Data.SetData(StandardDataFormats.Text, e.Items.);
}catch(Exception ex)
{
f.MessageBox(ex.Message);
}
}
private async void ListC_DragEnter(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Copy;
//IReadOnlyList<IStorageItem> files = await e.DataView.GetStorageItemsAsync();
}
private async void ListC_Drop(object sender, DragEventArgs e)
{
try
{
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await e.DataView.GetStorageItemsAsync();
if (items.Count > 0)
{
var storageFile = items[0] as StorageFile;
ListC.Items.Add(storageFile.Name);
}
}
}catch
{
f.MessageBox("nope");
}
I have populated my checkboxlist on the fly via callback like this:
<dx:ASPxComboBox ID="ASPxComboBox_Prot" runat="server" DataSourceID="SqlDataSource_Prot"
TextField="LIBELLE" ValueField="NO_PROT" ValueType="System.Int32">
<ClientSideEvents SelectedIndexChanged="function(s, e) { cbp_ProtOrdos.PerformCallback(s.GetValue());}" />
</dx:ASPxComboBox>
</td>
</tr>
</table>
<dx:ASPxCallbackPanel ID="ASPxCallbackPanel_ProtOrdo" runat="server"
ClientInstanceName="cbp_ProtOrdos" OnCallback="cbp_ProtOrdo_Callback">
<PanelCollection>
<dx:PanelContent>
<dx:ASPxCheckBoxList ID="CheckBoxList_Ordo" runat="server" ClientInstanceName="CheckBoxList_Ordo" ValueType="System.Int32" TextField="LIBELLE" ValueField="NO_ORDO">
</dx:ASPxCheckBoxList>
<dx:ASPxButton ID="ASPxButton_ProtOrdoGen" runat="server"
Text="Générer ordonnance & Planifier pour infirmier"
OnClick="ASPxButton_ProtOrdoGen_Click"
EnableDefaultAppearance="false" BackColor="Yellow" CssClass="bt" Theme="BlackGlass" ForeColor="Black">
</dx:ASPxButton>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
And on server side code:
protected void cbp_ProtOrdo_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
var panel = sender as ASPxCallbackPanel;
var cblist = panel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
cblist.DataSource = Outils.Get_ProtOrdo(ASPxComboBox_Prot.Value.ToString());
cblist.DataBind();
}
It works fine, but now I want to get the value that had been checked by the user. So I add the button to do that.
protected void ASPxButton_ProtOrdoGen_Click(object sender, EventArgs e)
{
//TabPage oPage = ASPxPageControl_DosSoin.TabPages.FindByName("Surveillance");
//ASPxPanel oPanel = (ASPxPanel)oPage.FindControl("ASPxPanel_ListSurveil");
//ASPxRoundPanel oRoundPnl = (ASPxRoundPanel)oPanel.FindControl("ASPxRoundPanel_ProtOrdo");
//ASPxCallbackPanel ocbpPanel = (ASPxCallbackPanel)oRoundPnl.FindControl("ASPxCallbackPanel_ProtOrdo");
//ASPxCheckBoxList cblist = (ASPxCheckBoxList)ocbpPanel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
List<string> selectItems_Ordo = new List<string>();
foreach (var oItem in CheckBoxList_Ordo.Items)
{
ListEditItem oNewChk = (ListEditItem)oItem;
if (oNewChk.Selected)
{
selectItems_Ordo.Add( oNewChk.Value.ToString());
}
}
foreach (var oItem in selectItems_Ordo)
{
if (DossierDuSoins.check_doublon_ordo(oItem.ToString(), Soin_Id) == 0)
DossierDuSoins.RamenerVal(DossierDuSoins.GetLibOrdo(oItem.ToString()), Soin_Id, oItem.ToString());
}
string TempId = "";
if (selectItems_Ordo.Count == 0)
{
lbl_err.Text = "Pas de médicament de sélectionné";
}
else
{
foreach (string selectItemId in selectItems_Ordo)
{
if (TempId != "")
TempId += ",";
TempId += selectItemId.ToString();
}
string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId;
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl));
}
}
The problem is that I can not get my checked value. Is that because the postback destroys all checkboxlists that I had constructed on the fly ?
Try this instead of using vars for selecting your checkbox list
foreach (ListItem yourItem in YourCheckBoxList.Items)
{
if (item.Selected)
{
// If the item is selected, Add to your list/ save to DB
}
else
{
// If item is not selected, do something else.
}
}
I've seen a lot of chatter on this topic. Though the examples and desired outcomes are always very specific and specialized. Any direction on this is appreciated.
In my Code: I am dynamically generated image and image URL.And add this image control in panel.I want to Put Image url in argument of temp() but i dont understand how can i do this
<td align="center" colspan="2" style="height: 200px; ">
<asp:Panel ID="Panel_pic1" runat="server">
</asp:Panel>
</td>
Code Behind:
var lasToThirteenthUploaded = ds.Tables["title"].Rows[ds.Tables["title"].Rows.Count - 13]["id"].ToString();
int ID13 = Convert.ToInt16(lasToThirteenthUploaded);//row.Field<int>("video_id");
Image img13 = new Image();
img13.ID = "image" + ID13;
string title13 = ds.Tables["title"].Rows[ds.Tables["title"].Rows.Count - 13]["title"].ToString();//row.Field<string>("title");
img13.ImageUrl = ds.Tables["title"].Rows[ds.Tables["title"].Rows.Count - 13]["path"].ToString();// ("image_path");
Panel_pic13.Controls.Add(img13);
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (Session["Name"] == null)
{
}
else
{
temp();
}
}
protected void temp()
{
}
Pass value from here
else
{
temp(img13.ImageUrl);
}
and grab it in
void temp(string imageurl)
{
}
you could use protected void temp(string imageurl) also