小编Nam*_*mek的帖子

在ListView内部的ViewCell内检测标签上的点击

我正在尝试处理类似的东西(从UI角度来看),以: 在此输入图像描述

为了调用两种不同的业务逻辑:

  • 点击ViewCell元素本身(在ListView内部) - 在示例中导航到不同的页面
  • 点击标签元素(可点击标签),它在给定的ViewCell元素内 - 在示例中删除给定对象或其他

我希望在ViewModel页面中有完整的"点击"逻辑.

基于Xamarin论坛上提出,我能够调用的"敲打"我的一些逻辑删除从细胞作用,但直接我的数据模型中-这在我的POV没有很好的解决办法,因为我想操纵我的收藏列表(所以最好的方法是在ViewModel页面上有这个逻辑.

我现在拥有的:

我的页面查看XAML代码如下所示:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App.Views.TestView">
  <ContentPage.Content>
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <ListView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" ItemsSource="{Binding MyItemsCollection}" SelectedItem="{Binding SelectedItem}">
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <StackLayout Orientation="Horizontal">

                  <!-- Name Label -->
                  <Label Text="{Binding Name}" VerticalOptions="CenterAndExpand" HorizontalOptions="StartAndExpand" />

                  <!-- Delete "Icon" -->
                  <Label Text="Clickable Label" VerticalOptions="CenterAndExpand" HorizontalOptions="EndAndExpand">
                    <Label.GestureRecognizers>
                      <TapGestureRecognizer Command="{Binding OnClickableLabel}" CommandParameter="{Binding .}" />
                    </Label.GestureRecognizers>
                  </Label>

                </StackLayout>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
  </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

我的页面查看C# …

.net c# xaml xamarin xamarin.forms

7
推荐指数
1
解决办法
5344
查看次数

使用Xamarin.Auth进行OAuth2身份验证 - 用户名和密码?

我在使用Xamarin.Auth进行OAuth2身份验证时遇到了一些问题.

从POSTMAN我通过GET方法向我的后端URL发送令牌请求:http: //example.com/backend/oauth/token 通过添加到标头:

授权,基本xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

并在URL中使用以下参数:

CLIENT_ID = backendClient

范围=读

grant_type =密码

用户名=管理员

密码=管理员

所以它就像:http: //example.com/backend/oauth/token?client_id = backEndClient&screen = read&grant_type = password&username = admin&password = admin

它给了我JSON,它看起来像:

{
"access_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"token_type": "bearer",
"refresh_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"expires_in": 9999,
"scope": "read"
}
Run Code Online (Sandbox Code Playgroud)

我想通过移动应用程序(使用Xamarin.Forms应用程序)对我的后端服务进行身份验证,并且我尝试使用Xamarin.Auth对我的后端进行身份验证 - https://developer.xamarin.com/guides/xamarin表单/网络服务/认证/ OAuth的/

确实使用OAuth2Authenticator,它至少能够"ping"我的后端(通过放置URL,clientIde等),因为它返回:

<UnauthorizedException>
    <error>unauthorized</error>
    <error_description>Full authentication is required to access this resource</error_description>
</UnauthorizedException>
Run Code Online (Sandbox Code Playgroud)

但是它的消息是以错误的方式发送的 - 至少我是这么认为的,因为标题中没有授权 +我没有看到任何将用户名和密码传递到OAuth2Authenticator的可能性.

有谁有想法,我怎么能这样做?或者我应该使用别的东西 - 不是Xamarin.Auth?

谢谢.

c# oauth-2.0 xamarin xamarin.auth xamarin.forms

5
推荐指数
1
解决办法
1642
查看次数

从 Spring Controller 中的文件 (JSONObject) 返回模拟的 JSON

我想模拟一些 JSON(我正在从文件中读取),并将其作为某些 Spring Controller 的结果返回。

文件中当然包含正确的 JSON 数据格式,例如:

{"country":"","city":""...}
Run Code Online (Sandbox Code Playgroud)

我的控制器看起来像:

@RestController
@RequestMapping("/test")
public class TestController {

    @Value("classpath:/META-INF/json/test.json")
    private Resource testMockup;

    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody JSONObject getTest() throws IOException {
        JSONObject jsonObject = new JSONObject(FileUtils.readFileToString(testMockup.getFile(), CharEncoding.UTF_8));
        return jsonObject;
    }
}
Run Code Online (Sandbox Code Playgroud)

读取文件本身等jsonObject本身没有问题, 调试 PoV 是正确的,但是我从浏览器获取HTTP 状态 406。我也试过只返回 String (通过返回jsonObject.toString()),而不是JSONObject. 然而,它会导致编码问题 - 因此来自浏览器的 JSON 不是 JSON 本身(一些额外的斜杠、引号等)。

有什么办法可以从文件中返回 JSON?

java spring json controller jsonobject

4
推荐指数
2
解决办法
1万
查看次数

PHP - MySQL试图设置value ="0" - 它是NULL

我只是想设置一些值="0",但它会自动转换为NULL.

$result_checkups = mysql_query("INSERT INTO TABLE1 (COL1, COL2) VALUES (".(!empty($COL1) ? "'$COL1'" : "NULL").", ".(!empty($COL2) ? "'$COL2'" : "NULL").") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)

这是我的代码 - 它看起来很奇怪,因为我需要设置NULL,当有人试图设置空字符串("").但现在,当时COL2="0",它NULL落后于MySQL(要清除,何时COL2="1",它是落后于MySQL的"1").哪里有问题?

MySQL表:

CREATE TABLE `TABLE1` (
  `COL1` TIMESTAMP NULL DEFAULT NOW(),
  `COL2` TINYINT(1) NULL);
Run Code Online (Sandbox Code Playgroud)

php mysql

-1
推荐指数
1
解决办法
476
查看次数